项目作者: mjebrahimi

项目描述 :
Unobtrusive Ajax Helpers (like MVC5 Ajax.BeignForm and Ajax.ActionLink) for ASP.NET Core
高级语言: C#
项目地址: git://github.com/mjebrahimi/AspNetCore.Unobtrusive.Ajax.git
创建时间: 2020-11-01T04:04:30Z
项目社区:https://github.com/mjebrahimi/AspNetCore.Unobtrusive.Ajax

开源协议:MIT License

下载


NuGet
NuGet
License: MIT
Build Status

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

  1. PM> Install-Package AspNetCore.Unobtrusive.Ajax

2. Add Service and Middleware

  1. public void ConfigureServices(IServiceCollection services)
  2. {
  3. //...
  4. services.AddUnobtrusiveAjax();
  5. //services.AddUnobtrusiveAjax(useCdn: true, injectScriptIfNeeded: false);
  6. //...
  7. }
  8. public void Configure(IApplicationBuilder app)
  9. {
  10. //...
  11. app.UseStaticFiles();
  12. //It is required for serving 'jquery-unobtrusive-ajax.min.js' embedded script file.
  13. app.UseUnobtrusiveAjax(); //It is suggested to place it after UseStaticFiles()
  14. //...
  15. }

3. Add Script Tag in Layout.cshtml

  1. <!--Place it at the end of the body and after jQuery -->
  2. @Html.RenderUnobtrusiveAjaxScript()
  3. <!-- Or you can reference your local script file -->
  4. @RenderSection("Scripts", required: false)
  5. </body>
  6. </html>

4. Use it

  1. @using (Html.AjaxBeginForm(new AjaxOptions
  2. {
  3. HttpMethod = "post",
  4. //Other options ...
  5. }))
  6. {
  7. }

Demo

Checkout AspNetCore.Unobtrusive.Ajax.Demo for more samples.

Demo

Contributing

Create an issue if you find a BUG or have a Suggestion or Question.

If you want to develop this project :

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request

Give a Star! ⭐️

If you find this repository useful, please give it a star. Thanks!

License

Copyright © 2020 Mohammd Javad Ebrahimi under the MIT License.