# Notification in Razor Pages

This article describes how to seamlessly integrate and configure the Telerik UI Notification for ASP.NET Core in Razor Pages applications.

## Referencing Handler Methods in Razor Pages

Razor Pages is an alternative to the MVC pattern that makes page-focused coding easier and more productive. This approach consists of a `cshtml` file and a `cshtml.cs` file (by convention, the two files have the same name).

The `cshtml.cs` file, known as the `PageModel`, contains handler methods that respond to HTTP requests. These methods are prefixed with `On` followed by the HTTP verb (for example, `OnGet`, `OnPost`, `OnPostRead`, `OnPostCreate`).

Handler methods declared in a `PageModel` can be referenced from any Razor Page using one of the following URL patterns:

* Using `Url.Page()`

  ```C#
  Url.Page("PageName", "HandlerName")
  // OR
  Url.Page("/FolderName/PageName", "HandlerName")
  ```

  For example, `Url.Page("Index", "Read")` references the `OnPostRead` or `OnGetRead` handler method in the `Index.cshtml.cs` file.

* Using a query string

  ```C#
  Url("/PathToPage?handler=HandlerName")
  ```

  For example, `Url("/Index?handler=Read")` references the `OnPostRead` or `OnGetRead` handler method in the `Index` page.

For more information on Razor Pages architecture and concepts, refer to [the official Microsoft documentation](https://learn.microsoft.com/en-us/aspnet/core/razor-pages/).

## Showing Notification on Post Request

The following example demonstrates how to display a Notification with data retrieved from a `PageModel` handler method through an AJAX POST request.

```Razor HtmlHelper
@page
@model NotificationIndexModel

@inject Microsoft.AspNetCore.Antiforgery.IAntiforgery Xsrf
@Html.AntiForgeryToken()	

<button id="showNotification" class="k-button">Show notification</button>

@(Html.Kendo().Notification()
	.Name("notification")
	.Width("20em")
	.Templates(t =>
	{
		t.Add().Type("info")
			.ClientTemplate("<div>TEXT: <span class='custom-style'>#: text #</span> </div> <div>TIME: <span class='custom-style'>#: time #</span> </div>");
	})
)
```

```Razor TagHelper
@page
@model NotificationIndexModel

@inject Microsoft.AspNetCore.Antiforgery.IAntiforgery Xsrf
@Html.AntiForgeryToken()	

<button id="showNotification" class="k-button">Show notification</button>

<kendo-notification name="notification" width="200">
    <templates>
        <notification-template type="info"
		template="<div>TEXT: <span class='custom-style'>#: text #</span> </div> <div>TIME: <span class='custom-style'>#: time #</span> </div>">
        </notification-template>
    </templates>
</kendo-notification>
```

```JS Scripts
<script>
	$(document).ready(function () {
		$("#showNotification").click(function () {
			$.ajax({
				url: '/NotificationIndex?handler=Read',
				type: "POST",
				contentType: "application/json; charset=utf-8",
				headers: {
					RequestVerificationToken: $('input:hidden[name="__RequestVerificationToken"]').val()
				},
				dataType: "json",
				success: function (response) {
					// Show notification based on the returned data from the server                    
					var notification = $("#notification").getKendoNotification();
					notification.show({
						text: response.Text,
						time: kendo.toString(new Date(response.Time), "dd MMMM yy hh:mm tt")
					}, "info");
				}
			});
		});
	});
</script>
```

```C# PageModel
public class NotificationIndexModel : PageModel
{
	public JsonResult OnPostRead()
    {
        NotificationModel model = new NotificationModel()
        {
            Text = "Notification Text",
            Time = DateTime.Now
        };
        return new JsonResult(model);
    }
}
```

For the complete project, refer to the [Notification in Razor Pages example](https://github.com/telerik/ui-for-aspnet-core-examples/blob/master/Telerik.Examples.RazorPages/Telerik.Examples.RazorPages/Pages/Notification/NotificationIndex.cshtml).

## See Also

* [Using Telerik UI for ASP.NET Core in Razor Pages](https://docs.telerik.com/aspnet-core/getting-started/razor-pages#using-telerik-ui-for-aspnet-core-in-razor-pages)
* [Client-Side API of the Notification](https://www.telerik.com/kendo-jquery-ui/documentation/api/ui/notification)
* [Server-Side HtmlHelper API of the Notification](https://www.telerik.com/aspnet-core-ui/documentation/api/notification)
* [Server-Side TagHelper API of the Notification](https://www.telerik.com/aspnet-core-ui/documentation/api/taghelpers/notification)
* [Knowledge Base Section](https://www.telerik.com/aspnet-core-ui/documentation/knowledge-base)
