如何在视图中显示用户名的此错误 [英] How to display this error of User Name exists in view

查看:83
本文介绍了如何在视图中显示用户名的此错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试

{

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[^]


这篇关于如何在视图中显示用户名的此错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆