簡體   English   中英

根據存儲過程的結果在asp.net中顯示警報

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM