Coder Social home page Coder Social logo

mjebrahimi / aspnetcore.unobtrusive.ajax Goto Github PK

View Code? Open in Web Editor NEW
61.0 3.0 5.0 783 KB

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

License: MIT License

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

aspnetcore.unobtrusive.ajax's Introduction

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

PM> Install-Package AspNetCore.Unobtrusive.Ajax

2. Add Service and Middleware

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

    <!--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>

4. Use it

@using (Html.AjaxBeginForm(new AjaxOptions
{
    HttpMethod = "post",
    //Other options ...
}))
{
}

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.

aspnetcore.unobtrusive.ajax's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar mjebrahimi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

aspnetcore.unobtrusive.ajax's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.