Reputation: 794
I'm having trouble posting my formdata back to the controller. I'm trying to implement a wizard in a MVC4 application, the wizard is based on a sample project from Nadeem Afana (http://afana.me/post/create-wizard-in-aspnet-mvc-3.aspx). I have downloaded the sample project and it's working great. In my project the code is also working fine except for one thing, the 'post' is not working (while the submit later IS working).
I've isolated the variables, and they look fine to me if I look at them in the debugger in Firefox
var data = $("form").serialize();
var url = '@Url.Action("Confirm", "Product")';
$.post(url, data, function (r)
{
// inject response in confirmation step
$(".wizard-step.confirm").html(r);
});
However, the action on the specified controller isn't begin called (I've put a breakpoint on it)
[HttpPost]
public ActionResult Confirm(ProductModel model)
{
// my code ...
return PartialView(model);
}
I have also tried
$.post("/Product/Confirm", $("form").serialize(), function (r)
using the URL instead of @Url.Action ... no change.
For the life of me I cannot figure out what I'm doing wrong or what it is I'm missing, I've been googling searching trying the whole afternoon.
Upvotes: 0
Views: 1559
Reputation: 13223
You need to install Fiddler (http://fiddler2.com/) and then use it to see exactly what request is being made (if any) and why it's failing. Honestly in my experience trying to fix Ajax issues without some sort of tool like Fiddler is practically impossible and certainly a big time sync...
Upvotes: 1
Reputation: 581
Why don't you try the full notation of the ajax call in case some default is messing you up?
mydata = $('form').serialize();
$.ajax({
url: '/Product/Confirm',
type: 'POST',
dataType: 'html',
data: mydata,
success: function() {
$(".wizard-step.confirm").html(r);
});
EDIT 1:
Error handling
error: function(response, status, error) {
alert(error);
}
Upvotes: 0