简体   繁体   中英

Can Not Set Toastr Message From Controller in ASP.NET MVC 5

I want to display toastr message from controller for that i Preferred Link but not working properly.

i pass message from controller like this

this.AddToastMessage("", "Menu Added Successfully", ToastType.Success);

message pass to view ... for that see my screenshot number 1

截图 1

But When I pass value to my helper class it will pass null i dont know how.?for that see my screenshot 2

截图 2

What i am doing wrong.? can anyone help me out.?

Create a partial view with name _Toastr.cshtml in your Shared folder where your _Layout.cshtml present.

And paste below code

@using WebApplicationMVC1.Models
@if (TempData.ContainsKey("Toastr"))
{
    Toastr toastr = TempData["Toastr"] as Toastr;
    @ToastrBuilder.ShowToastMessages(toastr);
}

And call this partial view on your _Layout.cshtml page in below of RenderSection line like

@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/toastr")
@Scripts.Render("~/bundles/bootstrap")
@RenderSection("scripts", required: false)

@Html.Partial("_Toastr")

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