0

我正在开发一个 ASP.NET MVC 3 项目,需要从服务器端验证中排除某些属性。我正在寻找类似这个问题的东西是否可以覆盖模型中属性的必需属性?但我不想再次绑定模型,因为我已经对其进行了更改(据我了解,这就是 TryUpdateModel 会做的)。

来自相关问题

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

我想验证已更新的模型,不包括某些属性。我应该只使用链接问题中建议的 hackedbychinese 之类的 TryUpdateModel 吗?它可以改变属性的值吗?

4

1 回答 1

0

我最终使用了 jquery 验证规则删除方法。

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

这将覆盖模型[Required]中传真属性上的标签,DisplayPhoneNumber因此它不再是必需的输入。

于 2012-11-29T16:09:25.443 回答