I am trying to test this model:
public class LogonModel
{
[Required(ErrorMessage="Username is required")]
public string Username { get; set; }
[Required(ErrorMessage = "Email is required")]
public string Email { get; set; }
[Required(ErrorMessage = "Password is required")]
public string Password { get; set; }
}
In this action:
public ActionResult Logon()
{
LogonModel model = new LogonModel();
return View(model);
}
In this view:
@model POCModelValidation.Models.LogonModel
@{
ViewBag.Title = "Index";
}
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<h2>Index</h2>
@using (Html.BeginForm())
{
<h3>username</h3>
@Html.EditorFor(model => model.Username)
<h3>@Html.ValidationMessageFor(model => model.Username)</h3>
<br />
<h3>Password</h3>
@Html.EditorFor(model => model.Password)
<h3>@Html.ValidationMessageFor(model => model.Password)</h3>
<br />
<h3>Email</h3>
@Html.EditorFor(model => model.Email)
<h3>@Html.ValidationMessageFor(model => model.Email)</h3>
<input type="submit" value="Submit"/>
}
.. And I can’t understand the template in which it works, but it never works for all three fields. In addition, if I fill out, leave, and then go back and delete the contents of the fields enough time, it ultimately works for all of them, but rarely for the first time, and never for all of them at the same time. <i> I have this line in myweb.config
...
<appSettings>
<add key="ClientValidationEnabled" value="true"/>
<add key="UnobtrusiveJavaScriptEnabled" value="true"/>
</appSettings>
...
And in _Layout:
...
<script src="@Url.Content("~/Scripts/jquery-1.4.4.min.js")" type="text/javascript"></script>
...
Any ideas?
source
share