简体   繁体   English

根据存储过程的结果在asp.net中显示警报

[英]Show alert in asp.net based on result from stored proc

I am wanting to show an alert based on the output param of a stored proc. 我想基于存储的proc的输出参数显示警报。 If it is true, then I want to show an alert. 如果是真的,那么我想显示一个警报。 Baffled by this in honesty. 对此感到困惑。

Here is the code I have so far, it does not like the Response.Redirect as it returns an error regarding it potentially being unsafe: 这是我到目前为止的代码,它不喜欢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();
}

Can anyone advise of the correct way to show a confirmation alert in ASP.net? 任何人都可以建议在ASP.net中显示确认警报的正确方法吗?

Thanks in advance. 提前致谢。

There isn't really one correct way, it really depends on the architecture you have going on for the front of the site, eg is it based on CSHTML/Ajax/Angular something else. 确实没有一种正确的方法,它实际上取决于您在网站前端进行的架构,例如,它是否基于CSHTML / Ajax / Angular。

The code you have shown is a bit of mix of various ideas. 您显示的代码有些杂乱无章。 One way to tidy it up would be to do something like this. 整理它的一种方法是做这样的事情。

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();
    }

As you can see I've added ?alert=true to the page URL. 如您所见,我已经将?alert = true添加到页面URL。 You would then run some javascript on page load to look for this parameter and if it exists show an alert box. 然后,您将在页面加载时运行一些javascript,以查找此参数,如果存在,则显示一个警告框。

It's important in all web programming to keep a clear idea of what happens on the server, what happens on the browser, and how you are communicating between the two. 在所有Web编程中,务必要清楚了解服务器上发生的情况,浏览器上发生的情况以及两者之间的通信方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM