Default model binder does not bind my model class
I am trying to make a post that should use the Default Model Binder functionality in ASP.NET MVC 2 but unfortunately I can't get through....
When I click on the checkout button I populate a form dinamically using jQuery code and then submit this form to the server. This is the form that get submitted
<form action="/x/Order/Checkout" id="cartForm" method="post">
<input name="__RequestVerificationToken" type="hidden" value="UDjN9RdWheKyWK5Q71MvXAbbDNel6buJd5Pamp/jx39InuyYIQVptcEubIA2W8DMUzWwnZjSGkLspkmDPbsIxy8EVuLvfCSZJJnl/NrooreouptwM/PaBEz2v6ZjO3I26IKRGZPqLxGGfITYqlf8Ow==">
<input id="CustomerID" name="CustomerID" type="hidden" value="1">
<input id="FirmID" name="FirmID" type="hidden" value="2">
<input type="hidden" name="CartItems[0].ServiceTypeID" value="1">
<input type="hidden" name="CartItems[0].Quantity" value="1">
<input type="hidden" name="CartItems[1].ServiceTypeID" value="2">
<input type="hidden" name="CartItems[1].Quantity" value="1">
</form>
This is the jQuery code that handle the submit event for the form
$("#cartForm").submit(function (event) {
event.preventDefault();
var form = $("#cartForm");
var panel = form.parent();
panel.parent().block();
$.ajax({
type: "post",
dataType: "html",
url: '<%: Url.Content("~/Order/Checkout") %>',
async: false,
data: form.serialize(),
success: function (response, status, xml) {
panel.parent().unblock();
},
error: function (response) {
panel.parent().unblock();
}
});
});
This is the controller action that should be get called
[HttpPost]
[ValidateAntiForgeryToken]
public virtual ActionResult Checkout( CartModel cart ) {
}
And finally this is the CartModel class involved
public class CartModel : BaseModel
{
public int CustomerID { get; set; }
public int FirmID { get; set; }
public List<CartItemModel> CartItems { get; set; }
public CartModel() {
CartItems = new List<CartItemModel>();
}
}
public class CartItemModel : BaseModel
{
public int ServiceTypeID { get; set; }
public int Quantity { get; set; }
}
But the default Model Binder does not bind the web form data to a CartModel class. Using Fiddler I have been able to see that the data sent to the server is correct as you can see from the following snapshot
Any suggestion?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论