如何将消息从我的存储库类返回到我的控制器,然后返回到我在 asp.net-mvc 中的视图?
我用它来检查表中现有的 emailId 并将其插入...当用户尝试使用现有的 mailId 注册时,如何向用户显示消息效果很好...
if (!taxidb.Registrations.Where(u => u.EmailId == reg.EmailId).Any())
{
taxidb.Registrations.InsertOnSubmit(reg);
taxidb.SubmitChanges();
}
并且我的控制器有这个,
RegistrationBO reg = new RegistrationBO();
reg.UserName = collection["UserName"];
reg.OrgName = collection["OrgName"];
reg.Address = collection["Address"];
reg.EmailId = collection["EmailId"];
reg.Password = collection["Password"];
reg.CreatedDate = System.DateTime.Now;
reg.IsDeleted = Convert.ToByte(0);
regrep.registerUser(reg);
任何建议如何显示使用 asp.net mvc 的用户已经存在“EmailID”...
I use this for checking an existing emailId in my table and inserting it...It works fine how to show message to user when he tries to register with an existing mailId....
if (!taxidb.Registrations.Where(u => u.EmailId == reg.EmailId).Any())
{
taxidb.Registrations.InsertOnSubmit(reg);
taxidb.SubmitChanges();
}
and my controller has this,
RegistrationBO reg = new RegistrationBO();
reg.UserName = collection["UserName"];
reg.OrgName = collection["OrgName"];
reg.Address = collection["Address"];
reg.EmailId = collection["EmailId"];
reg.Password = collection["Password"];
reg.CreatedDate = System.DateTime.Now;
reg.IsDeleted = Convert.ToByte(0);
regrep.registerUser(reg);
Any sugesstion how to show "EmailID" already exists to the user with asp.net mvc...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
让
registerUser
存储库方法返回一个布尔值,指示它是否已更新数据库,以便控制器操作变为:并在您的视图中显示消息:
如果您正在使用推荐的强类型视图,那么您可以向您的视图模型添加一个布尔属性,该属性将指示是否发生数据库更新:
并在视图中测试模型值:
Make the
registerUser
repository method return a boolean value indicating whether it has updated the database so that the controller action becomes:and in your view show the message:
If you are using strongly typed view which is recommended then you may add a boolean property to your view model which will indicate whether the database update took place:
and in the view test the model value: