Unobtrusive Ajax Helpers (like MVC5 Ajax.BeignForm and Ajax.ActionLink) for ASP.NET Core
Unobtrusive Ajax Helpers (like MVC5 Ajax.BeignForm and Ajax.ActionLink) for ASP.NET Core.
[AntiForgeryTokenValidation]
.[AjaxOnly]
attribute to limit Ajax-only Actions.httpRequest.IsAjaxRequest()
extension method to check if the request is Ajax and decides to return PartialView or JSON result.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 |
PM> Install-Package AspNetCore.Unobtrusive.Ajax
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()
//...
}
<!--Place it at the end of the body and after jQuery -->
@Html.RenderUnobtrusiveAjaxScript()
<!-- Or you can reference your local script file -->
@RenderSection("Scripts", required: false)
</body>
</html>
@using (Html.AjaxBeginForm(new AjaxOptions
{
HttpMethod = "post",
//Other options ...
}))
{
}
Checkout AspNetCore.Unobtrusive.Ajax.Demo for more samples.
Create an issue if you find a BUG or have a Suggestion or Question.
If you want to develop this project :
git checkout -b my-new-feature
git commit -am 'Add some feature'
git push origin my-new-feature
If you find this repository useful, please give it a star. Thanks!
Copyright © 2020 Mohammd Javad Ebrahimi under the MIT License.