簡體   English   中英

使用asp.net MVC在按鈕單擊成功時查看袋消息無法正常工作?

[英]view bag message not working properly on button click success using asp.net mvc?

當我單擊“保存”按鈕時,將顯示成功警報消息,但我僅要求成功保存功能,然后才應顯示成功警報消息。

在我的代碼中,我在單擊按鈕時寫了成功警報消息,因此它無法正常工作。 如何在id="bn-success"查看包消息中調用id="bn-success"

<input type="submit" name="actionType" id="bn-success" value="Save" class="btn btn-rounded btn-inline btn-success" />

控制器:

[HttpPost]
        [AllowAnonymous]
        [ValidateAntiForgeryToken]
        public ActionResult Domain(Domain domain)
        {
            try
            {
                int refID = Convert.ToInt32(Session["RefID"]);
                if (ModelState.IsValid && refID > 0)
                {
                    userType type = new userType();
                    int id = type.AddDomain(domain, refID);
                    if (id != 0)
                    {
                        ViewBag.Message = "Domain added successfully";
                    }
                }
                return View();
            }
            catch
            {
                return View();
            }

        }

警報消息:

 $('#bn-success').on('click', function() {
        $.notify({
            icon: 'font-icon font-icon-check-circle',
            title: '<strong>Heads up!</strong>',
            message: @ViewBag.Message
        },{
            type: 'success'
        });
    });

錯誤

'@ ViewBag.Message'

$('#bn-success').on('click', function() {
    $.notify({
        icon: 'font-icon font-icon-check-circle',
        title: '<strong>Heads up!</strong>',
        message: '@ViewBag.Message'
    },{
        type: 'success'
    });
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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