Jquery 文档准备就绪时加载部分视图
我正试图在页面加载完成时,用数据库中的项目自动填充无序列表()。我需要知道的是如何得到这些物品。我认为控制器和PartialView没有任何问题。我所需要的就是如何从索引页调用它 以下代码来自索引页:Jquery 文档准备就绪时加载部分视图,jquery,ajax,asp.net-mvc,model-view-controller,partial-views,Jquery,Ajax,Asp.net Mvc,Model View Controller,Partial Views,我正试图在页面加载完成时,用数据库中的项目自动填充无序列表()。我需要知道的是如何得到这些物品。我认为控制器和PartialView没有任何问题。我所需要的就是如何从索引页调用它 以下代码来自索引页: <div class="contentRight"> <span class="contentRightHeader">Most Followed Questions ·</span><span class="contentRigh
<div class="contentRight">
<span class="contentRightHeader">Most Followed Questions ·</span><span class="contentRightViewAll"> View all</span>
<ul>
<!--<li>Why do we drink and whats the effects on the body</li>
<li>Why do we drink and whats the effects on the body</li>-->
</ul>
</div>
最后,从我的观点来看:
@foreach (var item in ViewBag.Questions)
{
@item.Topic Deadline:
@item.Deadline
}
谢谢你的帮助 您可以通过两种方式来实现:首先,在局部视图中构造html,然后在ul-like中调用它
@foreach (var item in ViewBag.Questions)
{
"<li>"+@item.Topic Deadline:@item.Deadline+"</li>"
}
您可以通过两种方式来实现这一点:首先在局部视图中构造html,然后在ul-like中调用它
@foreach (var item in ViewBag.Questions)
{
"<li>"+@item.Topic Deadline:@item.Deadline+"</li>"
}
尝试使用
Ajax
在加载index
page后加载列表尝试使用Ajax
在加载index
页面后加载列表
<div class="contentRight">
<span class="contentRightHeader">Most Followed Questions ·</span><span class="contentRightViewAll"> View all</span>
<ul>
@Html.RenderPartial("_ListMostFollowedQuestions")
</ul>
</div>
$(function(){
$.ajax({
type:'POST',
url:'/path/to/partial',
dataType:'html',
success:function(data){
$("span.contentRightHeader ul").append(data);
}
});
});