I use ASP.NET MVC Razor And Data Annotation validators. My model:
public class Person { public int id { get; set; } [Required] public string FirstName { get; set; } [Required] public string LastName { get; set; } }
FirstName And LastName - Requerd. I want to change FirstName. My method:
public ActionResult Edit([Bind(Include = "FirstName")]Person person) { var p = GetPerson(); if (TryUpdateModel(p)) {
But TryUpdateModel always returns false. because LastName is not valid.
How to prevent LastName validation check in TryUpdateModel?
Note:
- The code is simplified. my real code is very complicated.
- I need to use Requierd for two properties
- I do not want to use another model class
Morteza
source share