我想在不知道键值的情况下从modelState中获取所有错误消息.循环以获取ModelState包含的所有错误消息.
我怎样才能做到这一点?
我正在使用
modelstate.Adderror("test","test message")
Run Code Online (Sandbox Code Playgroud)
如何在控制器本身中获得此模型状态值.
就像我需要在控制器中获得"test"的错误消息.
我已经创建了一个Edit Action方法,但它不在ModelState.isValid中.我该如何检查错误?
public PartialViewResult UpdateAccountDetails(string accountNumber)
{
CreditReportService crService = new CreditReportService();
AccountInfo account = new AccountInfo();
account.Account = service.GetAccountDetails(accountNumber);
account.AccountStatuses = service.GetAccountStatuses();
account.AccountTypes = service.GetAccountTypes();
account.CreditTerms = service.GetCreditTerms();
return PartialView("_UpdateAccountDetails", account);
}
[HttpPost]
public ActionResult UpdateAccountDetails(Account account)
{
if (ModelState.IsValid)
{
service.SaveAccount(account);
TempData["message"] = "Account has been updated successfully!";
AccountInfo accountInfo = new AccountInfo();
accountInfo.AccountStatuses = service.GetAccountStatuses();
accountInfo.AccountTypes = service.GetAccountTypes();
accountInfo.CreditTerms = service.GetCreditTerms();
return PartialView("_UpdateAccountDetails", accountInfo);
}
else
{
return PartialView("_UpdateAccountDetails", account);
}
}
Run Code Online (Sandbox Code Playgroud)