我需要在我的控制器中验证 mvc 中的一些东西我必须
@Html.ValidationMessageFor(model => model.somestring)// in the view
if (model.string = some condition)
ModelState.AddModelError("somestring", "String cannot be empty");// in the controller
但是如果在我看来我有一个自定义对象,例如
@Html.ValidationMessageFor(model => model.someobject.somestring)// in the view
我如何验证它?以下语法是否正确?
if (model.someobject.somestring = some condition)
ModelState.AddModelError("somestring", "String cannot be empty");// in the controller