Ranjith Kumar Nagiri
Ranjith Kumar Nagiri

Reputation: 863

Required field is not working in mvc4

in my model i have email, password,new password and re-type new password property's are there.

[Required]
    [DataType(DataType.EmailAddress)]
    [Display(Name = "Email: ")]
    public string Email { get; set; }

    public bool changePassword { get; set; }
    [Required]
    [DataType(DataType.Password)]
    [Display(Name = "Old Password:*")]
    public string OldPassword { get; set; }

    [Required]
    [DataType(DataType.Password)]
    [Display(Name = "New Password:*")]
    public string NewPassword { get; set; }

    [Required]
    [DataType(DataType.Password)]
    [Display(Name = "Re-type Password:*")]

i put required to all controls. in my view i devide those controls like, Email in one form and remaining are another form. my problem is email validation is working in form form.

coming to another form validation is not working.

can any one suggest me to come out this problem.

Upvotes: 1

Views: 2031

Answers (2)

Shiva Saurabh
Shiva Saurabh

Reputation: 1289

in your cshtml file say layout try putting this

@Scripts.Render("~/Scripts/jquery.validate.min.js")
@Scripts.Render("~/Scripts/jquery.validate.unobtrusive.min.js")

this might work.

Upvotes: 1

Tom Stickel
Tom Stickel

Reputation: 20421

Make sure that you are submitting to proper controller and using the ModelState.IsValid

// POST: /Orders/Create 
[AcceptVerbs(HttpVerbs.Post)] 
public ActionResult Create(Orders order) {
    if (ModelState.IsValid) {
        try {
        .....

Upvotes: 1

Related Questions