Telerik Notifications in .net core razor page

1 Answer 101 Views
Notification
Anjali
Top achievements
Rank 2
Anjali asked on 24 Aug 2023, 03:56 AM

I need to show the notification on my razor page. The message comes from the controller. Below is what I have:

 

 public ActionResult Index()
        {
           

            if (test == "Success")
                return View("Successfully stored);
            else
                return View("failed to store");
        }

 

On My razor page, I want to show the Success notification message when test is Success otherwise show the failure message. How can I achieve this. I don't want to click any button to show the success and failure notification.

1 Answer, 1 is accepted

Sort by
0
Accepted
Mihaela
Telerik team
answered on 28 Aug 2023, 04:32 PM

Hello Nitu,

You could access the message text from the Model and pass it to the show() method of the Notification, as per the example below:

  • PageModel
    public class IndexModel : PageModel
    {
        public string Message { get; set; }

        public void OnGet(string message)
        {
            if (message == "Success")
                Message = "Successfully stored";
            else
                Message = "failed to store";
        }
    }
  • Page
@page
@model IndexModel
@{
    ViewData["Title"] = "Index";
}

@(Html.Kendo().Notification()
    .Name("notification")
    .Position(p => p.Pinned(true).Top(30).Right(30))
    .HideOnClick(true)
    .AutoHideAfter(0)
)

<script>
    $(document).ready(function () {
        var notification = $("#notification").data("kendoNotification"); //Get a reference to the Notification component
        var msg = '@Model.Message'; //Get the message from the Model
        if (notification) {
            notification.show(msg); //Show the Notification with the respective message
        }
    });
</script>

If any questions pop up, feel free to let me know.

 

Regards,
Mihaela
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages. If you're new to the Telerik family, be sure to check out our getting started resources, as well as the only REPL playground for creating, saving, running, and sharing server-side code.
Tags
Notification
Asked by
Anjali
Top achievements
Rank 2
Answers by
Mihaela
Telerik team
Share this question
or