【发布时间】:2018-03-21 18:03:20
【问题描述】:
我是这里的初学者。我正在处理这个ASP.NET Core MVC 项目,我正在尝试将Update.cshtml 中的<div id="divInventoryPageLoad"></div> 中的Index.cshtml 作为PartialView 加载。但是,当我运行代码时,Index.cshtml 中的<div id="divInventoryPageLoad"></div> 没有任何输出。在从浏览器检查Inspect Element 时,我看到我收到了错误:POST http://localhost:52880/Inventory/Update 500 (Internal Server Error)
Index.cshtml
<div class="pm-body clearfix">
<div role="tabpanel">
<ul class="tab-nav" role="tablist">
<li class="active" role="presentation">
<a href="#inventoryDetails" aria-controls="inventoryDetails" role="tab" data-toggle="tab" aria-expanded="true" onclick="LoadInventoryUpdateDetails(@ViewBag.InventoryId)">Inventory Details</a>
</li>
<li id="inventorylocatetab">
<a href="#inventoryLocate" aria-controls="inventoryLocate" role="tab" data-toggle="tab" aria-expanded="true" onclick="LoadInventoryLocate()">Inventory Locate</a>
</li>
</ul>
</div>
<div id="divInventoryPageLoad"></div>
</div>
@section Scripts{
<script type="text/javascript">
$(document).ready(function () {
$('#divInventoryPageLoad').load('/Inventory/Update', { Id:@ViewBag.InventoryId }, function() {
});
})
function LoadInventoryUpdateDetails(Id) {
$('#divPageLoad').load('/Inventory/Update', { Id:Id }, function() {
});
}
function Locate() {
$('#divPageLoad').load('/Inventory/Locate');
}
</script>
}
控制器
// GET: /Inventory/
public IActionResult Index(int Id)
{
ViewBag.InventoryId = Id;
return View();
}
// GET : ~/Inventory/Update/Id
public IActionResult Update(int Id)
{
...
}
当我在breakpoints 的帮助下进行测试时,Update 的 ActionMethod 没有受到影响。怎么办?
【问题讨论】:
-
你试过像:
$('#divInventoryPageLoad').load('/Inventory/Update?id='+@ViewBag.InventoryId)吗? -
@EhsanSajjad。有效!您能否将其发布为答案,以便我将其标记为正确答案?
-
添加为答案。
标签: jquery asp.net-mvc asp.net-core-mvc partial-views