如何将消息从我的存储库类返回到我的控制器,然后返回到我在 asp.net-mvc 中的视图?

发布于 2024-09-01 23:27:38 字数 690 浏览 4 评论 0原文

我用它来检查表中现有的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

晌融 2024-09-08 23:27:38

registerUser 存储库方法返回一个布尔值,指示它是否已更新数据库,以便控制器操作变为:

if (!regrep.registerUser(reg))
{
    ViewData["message"] = string.Format("{0} already exists", reg.EmailId);
}

并在您的视图中显示消息:

<div><%= Html.Encode(ViewData["message"]) %></div>

如果您正在使用推荐的强类型视图,那么您可以向您的视图模型添加一个布尔属性,该属性将指示是否发生数据库更新:

model.EmailId = reg.EmailId;
model.IsEmailExists = !regrep.registerUser(reg);
return View(model);

并在视图中测试模型值:

<% if (Model.IsEmailExists) { %>
    <div><%= Html.Encode(Model.EmailId) %> already exists</div>
<% } %>

Make the registerUser repository method return a boolean value indicating whether it has updated the database so that the controller action becomes:

if (!regrep.registerUser(reg))
{
    ViewData["message"] = string.Format("{0} already exists", reg.EmailId);
}

and in your view show the message:

<div><%= Html.Encode(ViewData["message"]) %></div>

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:

model.EmailId = reg.EmailId;
model.IsEmailExists = !regrep.registerUser(reg);
return View(model);

and in the view test the model value:

<% if (Model.IsEmailExists) { %>
    <div><%= Html.Encode(Model.EmailId) %> already exists</div>
<% } %>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文