如何在C#中通过else语句触发弹出窗口
您好,我正在使用 MVC3,并且处于 C# 环境中。我希望在满足 else 语句时有一个弹出显示。 代码如下所示:
if (validate.Count < 1) {
db.TutorStudents.Add(tutorStudent);
db.SaveChanges();
return RedirectToAction("Index");
} else {
// need some form of popup message here that does not redirect the user
}
我一直在搜索并找到了JQuery解决方案,但它们对点击结果起作用......相反,我希望弹出窗口在到达else语句时起作用。欢迎任何解决方案。
先感谢您
Hi i'm using MVC3 and i'm in the C# environment. I would like to have a popup show when an else statement is satisfied.
the code looks like this:
if (validate.Count < 1) {
db.TutorStudents.Add(tutorStudent);
db.SaveChanges();
return RedirectToAction("Index");
} else {
// need some form of popup message here that does not redirect the user
}
I've been searching and I found JQuery solutions, but they work on a click result right... rather, I want the popup to work when the else statement is reached. Any solution is welcome.
Thank you in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您无法直接从服务器在客户端显示弹出窗口。
但是您可以将一些标记值放入
ViewData
或ViewBag
并将该值传递给视图中的脚本:操作中
在视图中的
You can't show popup on the client side from the server directly.
But you can put some marker value to the
ViewData
orViewBag
and pass this value to the script in your view:in the action
in the view
尝试:
并在视图中:
更新: 您无法通过 Web 应用程序中的 C# 向用户显示弹出窗口。因为 C# 在服务器上运行,所以您必须创建客户端代码才能在最终用户浏览器上运行。因此,您必须通过 C# 创建逻辑来控制 App 并生成 HTML(和/或 JavaScript、jQuery、CSS)以实现您的目的。
try:
and in view:
UPDATE: You can't show a popup to user via C# in Web-Apps. Because C# runs at server, and you have to create a client-side code to run on end-users browser. So, you must create a logic via C# to control App and generate HTML (and/or JavaScript, jQuery, CSS) to achieve your purpose.