I applied sample codes with the book Pro ASP.NET MVC Framework.
[AcceptVerbs(HttpVerbs.Post)]
public ViewResult CheckOut(Cart cart, FormCollection form)
{
if (cart.Lines.Count == 0)
{
ModelState.AddModelError("Cart", "Sorry, your cart is empty");
return View();
}
if (TryUpdateModel(cart.ShippingDetails, form.ToValueProvider()))
{
orderSubmitter.SubmitOrder(cart);
cart.Clear();
return View("Completed");
}
else
{
return View();
}
}
But when I tried to complete order form in the browser, it showed the following error message:
Value cannot be null or empty. Parameter name: name Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: Value cannot be null or empty. Parameter name: name
The sample codes in the book are based on ASP.NET MVC1 but I am running them on VS 2010 with ASP.NET MVC 2. And it seems to be some kind of changes in ToValueProvider() method.
How can I fix this problem and make the mvc application run normally?Thanks very much.