【发布时间】:2020-06-30 15:58:12
【问题描述】:
我需要一些帮助来显示来自数据库的正确过滤数据。 如果用户按下按钮,则会显示一个带有部分视图的屏幕。每个局部视图都是一个模型,其中包含自己的数据。我使用 ajax 使其更具动态性。
控制器:
[HttpPost]
public JsonResult Test2(int id)
{
List<Location> p = _context.Locations.Where(x => x.CategoryId.Equals(id)).ToList();
return Json(p);
}
局部视图:
<div class="sidebar_container" id="style-3">
<div class="sidebar_list" id="locatieLijstAfter">
</div>
</div>
脚本:
function yoo(id) {
$.ajax({
type: 'POST',
url: '/Home/Test2',
data: { 'id': id },
success: function(result){
var p = "";
for (var i = 0; i < result.length; i++) {
$('#locatieLijstAfter').html('< partial name="../Shared/_LocationItemPartial.cshtml" ' + 'model = "' + result[i] + '" /> ');
}
}
这就是我现在拥有的,但是当我运行它时会发生这种情况。 enter image description here
【问题讨论】: