我有一个 ASP.NET Core MVC Web 应用程序,我尝试将其托管在 IIS 中(作为嵌套应用程序)。问题是,当我运行具有部分视图(显示表格的列表对象)的页面时,部分视图不会显示。
我已经检查了部分视图构建内容并将其设置为“内容”。完整页面具有搜索功能,可以编辑部分列表页面。从 Visual Studio 运行时效果很好
在我的控制器中,我有:
// GET the view list page
[Authorize]
public IActionResult ViewList()
{
return View();
}
// GET partial page for the List view
[Authorize]
public IActionResult ListPartial(string type = "all")
{
var items = GetListItems(type);
// set the found items in the model and return view with model
var model = new ItemModel { items = items };
return PartialView("_ItemsList", model);
}
然后在项目完整页面中,我有:
<link rel="stylesheet" href="~/css/ItemView.css" />
<div>
<br />
<h1 class="display-4">Item View</h1>
<center><input style="justify-content: center;" class="search" id="search" name="search" type="text" placeholder="Search..." /></center>
<div id="partialView"></div>
</div>
@section Scripts{
<script>
$('#partialView').load("/Controller/ListPartial")
$(function () {
$("#search").keyup(function () {
$.ajax({
type: "Get",
url: "/Controller/ListPartial?searchText=" + $(this).val(),
success: function (data) {
$("#partialView").html("");
$("#partialView").html(data);
},
error: function (response) {
console.log(response.responseText);
}
});
});
});
</script>
}
这是部分商品列表页面:
@model ItemsModel;
<link rel="stylesheet" href="~/css/ItemList.css" />
<center>
<table class="table">
<thead>
<tr>
<th scope="col">Name</th>
<th scope="col" style="">Description</th>
<th scope="col" style="">Price</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model.items)
{
<tr>
<td scope="row">@item.Name</td>
<td scope="row">@item.Description</td>
<td scope="row">@item.Price<br></td>
</tr>
}
</tbody>
</table>
</center>
当我在 IIS 中运行网站并转到
itemList
页面时,没有显示部分页面,仅显示搜索栏。如果我输入路径 website/controller/ListPartial
,那么我会看到部分页面自行显示,因此我知道它已正确发布,但它不会像从 Microsoft Visual Studio 运行时那样显示。检查页面显示没有错误或加载失败。
如果您对为什么会发生这种情况有任何想法,请告诉我。