My asp.net 4 MVC web app defines validation requirements in the model:
[Required(ErrorMessage = "The \"first name\" is required")]
public string FirstName { get; set; }
And enforces them in the view:
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
...
@Html.TextBoxFor(model => model.FirstName, new { @class = "input-default" })
@Html.ValidationMessageFor(model => model.FirstName)</td>
...
How can I do similar validation in a form that isn't tied to the model?
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
...
<input class="FirstName" type="text" value="" />
// Validate that the first name exists when they leave the control or submit the form.
...
Thanks!
< ...
Go to the complete details ...