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?