1

ページの読み込みが完了したときと同様に、順序付けられていないリスト()の1つに自分のDBのアイテムを自動的に設定しようとしています。私が知る必要があるのは、アイテムを入手する方法です。私はControllerとPartialViewに問題はないとは思わない。私が必要とするのは、インデックスページから呼び出す方法だけです。ドキュメントの準備が完了したときにパーシャルビューをロード

次のコードでは、インデックスページからです:

<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> 

このコードは、コントローラからである:私のpartialViewから

public PartialViewResult _ListMostFollowedQuestions() 
    { 
     QuestionManager qman = new QuestionManager(); 
     ViewBag.Questions = qman.ListMostFollowedQuestions(3); 
     return PartialView("_ListMostFollowedQuestions"); 
    } 

そして最後に:用

@foreach (var item in ViewBag.Questions) 
{ 
@item.Topic Deadline: 
    @item.Deadline  
} 

感謝助けて!

+0

'index'ページを読み込んだ後に' Ajax'を使ってリストを読み込もうとすると –

答えて

1

あなたの部分図で最初の二つの方法でそれを行うことができますHTMLを構築し、

@foreach (var item in ViewBag.Questions) 
{ 
"<li>"[email protected] Deadline:@item.Deadline+"</li>" 
} 

ようUL内で呼び出すと

<div class="contentRight"> 
      <span class="contentRightHeader">Most Followed Questions ·</span><span class="contentRightViewAll"> View all</span> 
      <ul> 
       @Html.RenderPartial("_ListMostFollowedQuestions") 
      </ul> 
     </div> 

に第二の方法は、ajax方法では、あなたのインデックスページ

$(function(){ 

$.ajax({ 
type:'POST', 
url:'/path/to/partial', 
dataType:'html', 
success:function(data){ 
$("span.contentRightHeader ul").append(data); 
} 

}); 

}); 
関連する問題