ViewModel not populated after the form is submitted using ActionLink
My view model is not getting populated when I submit the form using the ActionLink. Here is jquery code to submit the form:
$(document).ready(function () {
// attach the event to submit the form when button is clicked
$("#lnkSubmit").click(function () {
// submit the form
$("#CustomerRequestForm").submit();
});
});
Onsubmit the controller action is called but all the prop开发者_开发知识库erties of the viewmodel are null.
UPDATE 1:
here is the form code
@using (Html.BeginForm("AddCustomer","Customer",FormMethod.Post,new { id = "CustomerRequestForm" }))
I will answer your question with the following disclaimer:
Use submit buttons to submit forms, not links
This being said, make sure to cancel the default link action by returning false or you will get redirected before the form even had time to submit:
$("#lnkSubmit").click(function () {
$("#CustomerRequestForm").trigger('submit');
return false;
});
If the only thing you do is submit when clicking on an URL, why not use a button? They are made for that and people get what they do.
If you need to redirect to an other page. do it after the form is submitted and the code has run. (in your return)
精彩评论