在我的ASP.NET MVC Core项目中,以下视图中的JQuery在VS2015(使用IIS Express)上运行良好 . 但是,当相同的应用程序在 same 开发人员计算机(Windows 10)上发布到IIS时,它无法正常工作 . 在将表单提交给将数据保存到SQL Server Db的控制器之前,下面视图中的JQuery代码从视图中的 <td>@Html.EditorFor(r => r[i].SaleAmount, new { htmlAttributes = new { @class = "saleAmt" } })</td>
控件中的输入中删除$和逗号符号 . 但是,在将应用程序发布到IIS后,此功能无法正常工作 . 因此,该控件中的用户输入不会保存到数据库中 . 我可以在已发布的文件夹中看到完全相同的视图(我将其用作IIS中应用程序目录的物理路径) . 接受此问题,IIS中的整个应用程序正常工作 . Windows 10上的 IIS version
是10.0.14393.0:
UPDATE :
-
我错误地复制了错误的Jquery代码 . 我在下面的
View
中更正了Jquery . 但问题仍然存在:Jquery在VS2015(使用IIS Express)中工作,但在应用程序发布到同一台机器上的IIS后却没有 . -
我使用this article将我的ASP MVC Core应用程序发布到IIS . 该应用程序工作正常,除了我正在使用的唯一的Jquery(如下所示),似乎没有被调用 . IIS Express和本地IIS都在同一台计算机上 .
-
以下是项目的wwroot文件夹下的Javascript / Jquery相关文件夹结构 . 我看到相同的结构及其文件发布到项目的IIS物理路径目录中 .
Model :
public class SaleViewModel
{
[DisplayFormat(DataFormatString = "{0:C0}", ApplyFormatInEditMode = true)]
public float? SaleAmount { get; set; }
....
}
Controller :
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> UpdateSales(List<SaleViewModel> model, string returnUrl = null)
{
....
}
View :
@model IList<MyProj.Models.SaleViewModel>
....
<form id="target" asp-controller="DbRelated" asp-action="UpdateSales" asp-route-returnurl="@ViewData[" ReturnUrl"]" method="post" onsubmit="myJsFunction()">
<table class="table">
<thead>
....
</thead>
<tbody>
@for (int i = 0; i < Model.Count(); i++)
{
<tr>
<td>@Html.EditorFor(r => r[i].SaleAmount, new { htmlAttributes = new { @class = "saleAmt" } })</td>
....
</tr>
}
</tbody>
</table>
<button type="submit" class="btn btn-default">Save</button>
</form>
@section scripts
{
<script>
$("#target").submit(function () {
var textboxes = $('.saleAmt');
$.each(textboxes, function(index, item) {
var text = $(this).val().replace(/[$,]/g, '');
$(this).val(text);
});
});
</script>
}