如何在视图中显示用户名的此错误
尝试
{
if(storeView.storeid == 0)
{
// check如果usernamne存在
WebSecurity.CreateUserAndAccount(StoreModel.UserName,StoreModel.Password);
}
}
//如果用户不存在到此处,我想显示我在模型状态中添加的错误。
catch(MembershipCreateUserException e)
{
ModelState.AddModelError(UserName,输入用户存在);
返回View(storeModel);
}
//无法显示错误,因为未通过@ Html.ValidationMessage显示错误,显示黄色死亡屏幕
try
{
if (storeView.storeid == 0)
{
//check if usernamne exists
WebSecurity.CreateUserAndAccount(StoreModel.UserName, StoreModel.Password);
}
}
//if user doesn't exists comes here and i want to display the error i added in modelstate in view.
catch (MembershipCreateUserException e)
{
ModelState.AddModelError("UserName", "Entered User exists");
return View(storeModel);
}
//unable to display error in view not showing error through @Html.ValidationMessage, showing Yellow screen of Death
查看以下链接,它应该有帮助
http://stackoverflow.com/questions/20141102/mvc-4- return-error-message-from-controller-show-in-view [ ^ ]
Check with below link, it should help
http://stackoverflow.com/questions/20141102/mvc-4-return-error-message-from-controller-show-in-view[^]