Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use Microsoft.jQuery.Unobtrusive.Ajax with libman (Library manager) asp.net Core 2.1?

Tags:

I am trying to use unobtrusive ajax to update my partial views. Unfortunately I ran in to a problem when I was about to install the package, since Bower is not working (?) or recommended anymore according to https://docs.microsoft.com/en-us/aspnet/core/client-side/bower?view=aspnetcore-2.1. Instead they recommend us to use Libman.

I followed the steps from https://www.c-sharpcorner.com/article/unobtrusive-ajax-and-jquery-for-partial-updates-in-asp-net-mvc/.

So I have installed the nuget Microsoft.jQuery.Unobtrusive.Ajax-package, but how do I reference the ajax-package with libman?

I looked at this How to reference Microsoft.JQuery.Unobtrusive.Ajax within my ASP.NET Core MVC project answer but it only shows how to use Bower.

like image 812
Erik Sellberg Avatar asked Aug 30 '18 07:08

Erik Sellberg


People also ask

What is jQuery Ajax unobtrusive?

The jQuery Unobtrusive Ajax library complements jQuery Ajax methods by adding support for specifying options for HTML replacement via Ajax calls as HTML5 data-* elements. This project is part of ASP.NET Core. You can find samples, documentation and getting started instructions for ASP.NET Core at the Home repo.

What is unobtrusive Ajax in MVC?

The idea behind Unobtrusive AJAX is that AJAX behaviour is attached to form and anchor elements via HTML5 data-* attributes, instead of binding click event handlers in script blocks. In old MVC, these attributes can be generated from Html helpers: Ajax. BeginForm and Ajax. ActionLink and then setting some AjaxOptions .

What is client-side library in Visual Studio?

In this article, you will learn about Client-Side Package Management with Library Manager in Visual Studio. Library Manager is a lightweight, client-side library acquisition tool. Developers can retrieve libraries like jQuery, bootstrap, Vue. js, and others from various supported CDNs or even the file system.


1 Answers

I struggled with LibMan at first too. I found this guide that points out there's a GUI portion of LibMan. Using the UI portion of LibMan under the "project right click menu -> Add -> Client-Side Library" helped me figure out better ways to define which files I want and change the provider easier.

I ended up having most of my files come from cdnjs, but I set up jquery-ajax-unobtrusive to come from unpkg like so:

{
    "provider": "unpkg",
    "library": "[email protected]",
    "destination": "wwwroot/lib/jquery-ajax-unobtrusive/"
}
like image 80
Pinski Avatar answered Sep 22 '22 09:09

Pinski