[英]Show alert in asp.net based on result from stored proc
我想基于存储的proc的输出参数显示警报。 如果是真的,那么我想显示一个警报。 对此感到困惑。
这是我到目前为止的代码,它不喜欢Response.Redirect,因为它返回有关它可能不安全的错误:
public ActionResult NewCountry(string button,string Country,string Notes)
{
switch (button)
{
case "Save":
bool exists = InsertCountry(Country, Notes);
if (exists)
{
//Something
return Redirect("/Maintenance/Maintenance/Country");
}
else
return Redirect("/Maintenance/Maintenance/Country");
case "Cancel":
//Need to redirect to the countries page.
return Redirect("/Maintenance/Maintenance/Country");
}
return View();
}
任何人都可以建议在ASP.net中显示确认警报的正确方法吗?
提前致谢。
确实没有一种正确的方法,它实际上取决于您在网站前端进行的架构,例如,它是否基于CSHTML / Ajax / Angular。
您显示的代码有些杂乱无章。 整理它的一种方法是做这样的事情。
public ActionResult NewCountry(string button,string Country,string Notes)
{
switch (button)
{
case "Save":
bool exists = InsertCountry(Country, Notes);
if (exists)
{
return Redirect("/Maintenance/Maintenance/Country?alert=true");
}
else
return Redirect("/Maintenance/Maintenance/Country");
case "Cancel":
//Need to redirect to the countries page.
return Redirect("/Maintenance/Maintenance/Country");
}
return View();
}
如您所见,我已经将?alert = true添加到页面URL。 然后,您将在页面加载时运行一些javascript,以查找此参数,如果存在,则显示一个警告框。
在所有Web编程中,务必要清楚了解服务器上发生的情况,浏览器上发生的情况以及两者之间的通信方式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.