0

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

2
  • Which jquery libraries did you include? Sounds like the javascript isn't there. Commented Aug 21, 2014 at 15:41
  • <script src="~/Scripts/jquery-1.8.2.min.js"></script> <script src="~/Scripts/jquery.validate.min.js"></script> Commented Aug 21, 2014 at 15:53

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.