0

I am working on an ASP.NET MVC 3 project and need to exclude certain properties from server side validation. I am looking for something like in this question Is it possible to override the required attribute on a property in a model? but I do not want to bind the model again because I have already made changes to it (from my understanding that is what TryUpdateModel will do).

From related question

public ActionResult SomeAction()
{
 var model = new BaseModel();

 if (TryUpdateModel(model, null, null, new[] { "RequiredProperty" })) // fourth parameter is an array of properties (by name) that are excluded
 {
      // updated and validated correctly!
      return View(model);
 }
 // failed validation
 return View(model);
}

I want to validate the already updated model excluding certain properties. Should I just use TryUpdateModel like hackedbychinese suggested in the linked question? Could it change the values of the properties?

Community
  • 1
  • 1
d456
  • 1,147
  • 4
  • 13
  • 25

1 Answers1

0

I ended up using the jquery validation rules remove method.

$("#fax_DisplayPhoneNumber").rules("remove", "required");

This overrides the [Required] tag on the fax DisplayPhoneNumber property in the model so it is no longer a required input.

d456
  • 1,147
  • 4
  • 13
  • 25