Please help me on the following code. The Model class is using System.ComponentModel.DataAnnotation:
namespace Proj.Models
{
public class Customer
{
[Required]
public string CustomerID{get;set;}
[Required]
public string CustomerName{get;set;}
}
}
I have created a controller using this model, the action method being:
public class Customer:Controller
{
public ActionResult Details()
{
return View();
}
}
The razor view is Details.cshtml, having following markup and code:
@model Proj.Models.Customer
<form method="post">
@Html.EditorForModel()
<button>Submit!!</button>
</form>
However, when I click submit, no validation errors are seen as expected.
You need to create a method which takes your model as input like this:
The
[HttpPost]ensures that the method is only called on POST requests.