I have a simple ASP.NET MVC website where users can browse products and place pre-orders. To post it, they must provide a name and email address. The controller looks like this:
[HttpGet]
public ActionResult Product(string id)
{
return View(new ProductViewModel(id));
}
[HttpPost]
public ActionResult Product(PreOrderProductCommand command)
{
if (ModelState.IsValid)
{
command.Process();
return View("ThankYou");
}
else
return Product(command.Id);
}
ProductViewModel
It contains information about the product (name, description, price, etc.), and PreOrderProductCommand
contains only 3 string
properties: Id
, Name
and Email
. Now I want to enable client-side validation Name
and Email
with the help jquery.validate
and cannot figure out how to implement it. All online tutorials say I should use this code:
@Html.ValidationMessageFor(model => model.Email)
, ProductViewModel , Email
. PreOrderProductCommand
.
? ?