Reputation: 39
I have two models
public class UserDetail
{
[Required]
public string username { get; set; }
[Required]
public string name { get; set; }
public LogInDetail LogInDetail { get; set; }
}
and
public class LogInDetail
{
[Required]
public string username { get; set; }
[Required]
public string password { get; set; }
public UserDetail UserDetail { get; set; }
}
and a view having model UserDetail
@using (Html.BeginForm())
{
@Html.LabelFor(m=>m.LogInDetail.username)
@Html.EditorFor(m=>m.LogInDetail.username)
@Html.ValidationMessageFor(m=>m.LogInDetail.username)
@Html.LabelFor(m=>m.LogInDetail.password)
@Html.EditorFor(m=>m.LogInDetail.password)
@Html.ValidationMessageFor(m=>m.LogInDetail.password)
<input type="submit" value="Submit" />
}
if i try to submit the form without any entry it should show client side validation (as i have added [Required]
attribute to the properties of LogInDetails
). I have also added jquery library for validation. But i am not getting any client side validation error message. Please help me
Upvotes: 0
Views: 541
Reputation: 454
Make sure you include jquery.validate.unobtrusive.js too. For a complete list of requirements for automatic validation see this answer:
https://stackoverflow.com/a/8539211/848739
Upvotes: 1