I have a ajax that call action in my controller so when i enter submit it will not redirect or prevent default behaviour of action below is my ajax call
@using(Html.BeginForm("Send","Message",new { username = ViewBag.username },FormMethod.Post,new { id = "OptionForm" }))
{
@Html.AntiForgeryToken()
<div class="type_msg">
<div class="input_msg_write">
@Html.EditorFor(model => model.NewMessage.Content,
new { htmlAttributes = new { @class = "write_msg",@placeholder = "Type a message to " + ViewBag.info +"..." } })
</div>
</div>
}
everything work as expected after submit form, it will prevent default behaviour of my controller, My problem is when i submit the text in editor form don't remove, i mean i want to make editor or input empty after i submit form, how can i do that Thanks
Inside the success callback you can reset the values of all text boxes using jQuery like this:
success: function (data) {
$("input[type='text']").val("");
}
The $("input[type='text']") is the selector for all input controls of type text in the page. And you can use .val() method to set the value inside them to empty.
Thanks & Regards
Helping you always. Don't forget to click "Mark as Answer" on the post that helped you.
♠ ASP.NET Core Tutorials → Start from the Beginning and become an Expert in 30 days time ♠
Member
8 Points
85 Posts
make text empty in form after submit ajax
Jan 23, 2019 02:53 PM|hocamahdi99|LINK
I have a ajax that call action in my controller so when i enter submit it will not redirect or prevent default behaviour of action below is my ajax call
and here is my input form
everything work as expected after submit form, it will prevent default behaviour of my controller, My problem is when i submit the text in editor form don't remove, i mean i want to make editor or input empty after i submit form, how can i do that Thanks
All-Star
57864 Points
15491 Posts
Re: make text empty in form after submit ajax
Jan 23, 2019 02:59 PM|bruce (sqlwork.com)|LINK
In the Ajax success callback, add code to clear the text box, or use form.reset()
Member
8 Points
85 Posts
Re: make text empty in form after submit ajax
Jan 23, 2019 03:03 PM|hocamahdi99|LINK
Thanks for your respond how do i do that, cause i;m new in ajax
Participant
1253 Points
926 Posts
Re: make text empty in form after submit ajax
Jan 23, 2019 03:25 PM|yogyogi|LINK
You are using a jQuery AJAX method request
Inside the success callback you can reset the values of all text boxes using jQuery like this:
The $("input[type='text']") is the selector for all input controls of type text in the page. And you can use .val() method to set the value inside them to empty.
Thanks & Regards
♠ ASP.NET Core Tutorials → Start from the Beginning and become an Expert in 30 days time ♠
Member
8 Points
85 Posts
Re: make text empty in form after submit ajax
Jan 23, 2019 03:49 PM|hocamahdi99|LINK
noce thanks for your answer