ProgrammerGuide.Net | Step by Step Programmer Guide

Excluding Required Property from ModelState.IsValid | ASP.NET MVC Tutorial

You can exclude any property from validating using parameter binding. Set the exclude property in Bind attribute of a parameter as [Bind(Exclude = "Password")] 

In this way, by add exclusions to your action and explicitly state what can and can’t be binded we can achieve in ASP.NET MVC

public class Person 
{ 
    public int id { get; set; } 

    [Required] 
    public string FirstName { get; set; } 

    [Required] 
    public string LastName { get; set; } 
} 
FirstName And LastName are Requerd. I want to exclude LastName from validating:

public ActionResult Edit([Bind(Exclude = "LastName")]Person person)
{
    //your code for ModalState validation;    
}
Please click here for related products on Amazon!

Jayashee

Add comment

Want to Check Celebrities News?