2012-11-15 66 views
0

我正在开发ASP.NET MVC 3项目,需要从服务器端验证中排除某些属性。我正在寻找类似于这个问题Is it possible to override the required attribute on a property in a model?的东西,但我不想再次绑定模型,因为我已经对它进行了更改(根据我的理解,这是TryUpdateModel将执行的操作)。如何使用TryValidateModel验证模型时排除某些属性

从相关的问题

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); 
} 

我想验证排除某些属性已更新的模型。我应该只使用TryUpdateModel,就像链接问题中提到的hackedbychinese一样?它可以改变属性的值吗?

回答

0

我结束了使用jQuery验证规则删除方法。

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

这将覆盖在模型中的传真DisplayPhoneNumber财产[Required]标记,以便它不再是一个需要输入。

相关问题