简体   繁体   中英

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

When i click on save button then success alert message is displayed, but i require only save function successful then only success alert message should be displayed.

In my code i written success alert message in button on click so it is not working properly. how to call id="bn-success" in view bag message on success.

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

Controller:

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

        }

Alert message:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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