An open API service indexing awesome lists of open source software.

https://github.com/mjebrahimi/aspnetcore.unobtrusive.ajax

💻 Unobtrusive Ajax Helpers (like MVC5 Ajax.BeignForm and Ajax.ActionLink) for ASP.NET Core
https://github.com/mjebrahimi/aspnetcore.unobtrusive.ajax

ajax ajax-form ajax-helper ajax-upload asp-net-core asp-net-core-mvc aspnet-core aspnet-core-mvc aspnetcore aspnetcore-mvc aspnetcoremvc html-helper htmlhelper htmlhelpers jquery jquery-ajax unobstrusive

Last synced: 27 days ago
JSON representation

💻 Unobtrusive Ajax Helpers (like MVC5 Ajax.BeignForm and Ajax.ActionLink) for ASP.NET Core

Awesome Lists containing this project

README

        

[![NuGet](https://img.shields.io/nuget/dt/AspNetCore.Unobtrusive.Ajax?style=flat&logo=nuget&cacheSeconds=1&label=Downloads)](https://www.nuget.org/packages/AspNetCore.Unobtrusive.Ajax)
[![NuGet](https://img.shields.io/nuget/v/AspNetCore.Unobtrusive.Ajax?label=Version&cacheSeconds=1)](https://www.nuget.org/packages/AspNetCore.Unobtrusive.Ajax)
[![License: MIT](https://img.shields.io/badge/License-MIT-brightgreen.svg)](https://opensource.org/licenses/MIT)
[![Build Status](https://github.com/mjebrahimi/AspNetCore.Unobtrusive.Ajax/workflows/.NET/badge.svg)](https://github.com/mjebrahimi/AspNetCore.Unobtrusive.Ajax)

# AspNetCore.Unobtrusive.Ajax

Unobtrusive Ajax Helpers (like MVC5 **Ajax.BeignForm** and **Ajax.ActionLink**) for ASP.NET Core.

## Features

- Works with Upload file.
- Works with `[AntiForgeryTokenValidation]`.
- Has `[AjaxOnly]` attribute to limit Ajax-only Actions.
- Has `httpRequest.IsAjaxRequest()` extension method to check if the request is Ajax and decides to return PartialView or JSON result.
- Additional overloads for Ease of Use.
- Adds necessary JS script automatically when you use the Ajax Helpers and removes JS script when you no longer use it (Optional - is by default).
- Can use CDN URL (for jQuery files) instead of Embedded script (Optional - not by default).

## Method Usages

| Method | MVC 5
| ------------------------- | --------------------------------
| `Html.AjaxBeginForm` | instead of `Ajax.BeginForm`
| `Html.AjaxBeginRouteForm` | instead of `Ajax.BeginRouteForm`
| `Html.AjaxActionLink` | instead of `Ajax.ActionLink`
| `Html.AjaxRouteLink` | instead of `Ajax.RouteLink`

## Get Started

### 1. Install package

```ini
PM> Install-Package AspNetCore.Unobtrusive.Ajax
```

### 2. Add Service and Middleware

```csharp
public void ConfigureServices(IServiceCollection services)
{
//...
services.AddUnobtrusiveAjax();
//services.AddUnobtrusiveAjax(useCdn: true, injectScriptIfNeeded: false);
//...
}

public void Configure(IApplicationBuilder app)
{
//...
app.UseStaticFiles();

//It is required for serving 'jquery-unobtrusive-ajax.min.js' embedded script file.
app.UseUnobtrusiveAjax(); //It is suggested to place it after UseStaticFiles()
//...
}
```

### 3. Add Script Tag in Layout.cshtml

```html

@Html.RenderUnobtrusiveAjaxScript()

@RenderSection("Scripts", required: false)