Seems like there are a lot of ways to solve this problem.
Currently I make a partial view with a form like so:
<div id="container">
<form id="some-form">
<input id="some-text" type="text">
<input id="some-submit" type="submit">
</form>
</div>
then I hijack the submit with JQuery and do an ajax post and replace the form with another partial view:
$(function()
{
$('#some-form').submit(function(){
$.ajax({
type: "POST",
url: "/Controller/Action",
data: {someVal: $('#some-text').val()},
dataType: "html",
success: function (result) {
$('#container').html(result);
},
error: function (request, status, error) {
alert('Oh no!');
}
});
});
});
The controller would be like:
[HttpPost]
public ActionResult SomeAction(string someVal)
{
//Do something with text
return PartialView("SubmitSuccess");
}
My Question
What are other ways to accomplish the same thing and what are the pros and cons vs what I am doing?
Is Ajax.Form useful?
What I am doing doesn't seem like the right way to do it...?