如何在我的ASP.NET Core MVC项目中引用Microsoft.JQuery.Unobtrusive.Ajax [英] How to reference Microsoft.JQuery.Unobtrusive.Ajax within my ASP.NET Core MVC project
问题描述
我正在尝试使用Microsoft.JQuery.Unobtrusive.Ajax
.我首先使用NuGet安装该软件包,然后按预期可以在我的依赖项中看到它.
I am trying to use Microsoft.JQuery.Unobtrusive.Ajax
. I started by installing the package using NuGet and as expected I am able to see it among my dependencies.
我的问题是我找不到引用脚本的方法,因此无法在视图中使用它. 此处我看到我应该将其添加到布局中:
My problem is that I cant find a way to reference the script so I can use it within my view. Here I saw that I should add this to my layout:
<script src="~/lib/Microsoft.jQuery.Unobtrusive.Ajax/jquery.unobtrusive-ajax.min.js"></script>
但是该路径没有文件:
这是我的控制器动作:
[HttpPost]
public IActionResult OrderItem([Bind("Id,Quantity")] Item item)
{
return Json(new { foo= item.Id, boo= item.Quantity});
}
表格:
<form asp-action="OrderItem" asp-controller="Menu" method="POST" data-ajax="true" data-ajax-update="#divEmp" data-ajax-mode="replace" data-ajax-complete="onComplete" data-ajax-failure="onFailed" data-ajax-success="onSuccess">
<input asp-for="@i.Id" value="@i.Id" type="hidden" name="Id" />
<input asp-for="@i.Quantity" value="@i.Quantity" type="number" name="Quantity" class="form-group" />
<button class="btn btn-primary" type="submit">Add to Order</button>
</form>
我从控制器返回了JSON,但是我被重定向到显示JSON数据的页面.我的目标是使用JSON对象中的数据来更新同一视图中的组件.
I am returning a JSON from the controller but I am getting redirected to the page showing the JSON data. My goal is to use the data in the JSON object to update components within the same view.
推荐答案
我发现,在.NET生态系统中,Bower填补了NuGet无法交付静态内容文件所留下的空白. 播种后,我需要使用Bower安装需要从客户端访问的库. Bower会创建所需的静态内容.
I found that within the .NET ecosystem, Bower fills the void left by NuGet's inability to deliver static content files. Sow I need to use Bower to install the libraries that need to be accessible from the client side. Bower creates the required static content.
在我的情况下,我的asp.net核心项目未设置为使用Bower,因此我必须在项目中添加Bower配置文件.
in my case, my asp.net core project was not set up to use Bower so I had to add a Bower configuration file to my project.
有关参考,请检查此
这篇关于如何在我的ASP.NET Core MVC项目中引用Microsoft.JQuery.Unobtrusive.Ajax的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!