IIS不显示ASP.NET Core MVC Web应用程序的部分页面

nc1teljy  于 9个月前  发布在  .NET
关注(0)|答案(1)|浏览(119)

我有一个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运行时那样显示。检查页面显示没有错误或失败的加载。
如果你有任何想法,为什么会发生这种情况,请让我知道。

bvpmtnay

bvpmtnay1#

以下可能与您的问题相同。我的意思是发布到IIS的子网站后得到404。如果是的话,那么在取消之前更改URL可能是一种解决方法。

或者我们可以尝试将URL设置为结合根路径的变量,你可能会尝试,但我认为它看起来很丑。

// $('#partialView').load("/home/ListPartial");
$('#partialView').load("@Context.Request.PathBase/home/ListPartial");

相关问题