我正在为某个viewModel属性开发客户端和服务器端验证。在.cshtml文件中我放了这个:@Html.DropDownListFor(model=>model.EntityType.ParentId,Model.ParentTypeList,"")@Html.ValidationMessageFor(model=>model.EntityType.ParentId)在Controller中进行业务验证catch(BusinessExceptione){ModelState.AddModelError("EntityType.ParentId",Messages.CircularRe
我是MVC4的新手。在这里,我添加了ModelState.AddModelError消息以在无法执行删除操作时显示。@Html.ValidationMessage("CustomError")@Html.ValidationSummary(true)在我的Controller中publicActionResultDelete(stringid,stringproductid){intrecords=DeleteItem(id,productid);if(records>0){ModelState.AddModelError("CustomError","Theitemisremoved
我是MVC4的新手。在这里,我添加了ModelState.AddModelError消息以在无法执行删除操作时显示。@Html.ValidationMessage("CustomError")@Html.ValidationSummary(true)在我的Controller中publicActionResultDelete(stringid,stringproductid){intrecords=DeleteItem(id,productid);if(records>0){ModelState.AddModelError("CustomError","Theitemisremoved
我在我的Controller中添加了验证检查,如果验证失败,它会修改ModelState。例如:privateboolValidateMoney(stringraw,stringname,decimalmin,decimalmax){try{vardec=Convert.ToDecimal(raw);if(dec="+min);}elseif(dec>max){thrownewArgumentOutOfRangeException(name+"mustbe但是,我从来不知道要为ModelState.AddModelError中的key参数传递值。(在示例中,我只是将其设置为我的UI显示