2012-02-09 12 views
0

コントローラから送信したビューの値を取得できません。foreachループの項目の値を取得できません

私は2つの方法を試みましたが、それらをdivに表示させることはできません。テーブルやラベルに値を表示する必要があります。

コントローラー:

List<string> tsList = new List<string>(); 
ts.tarih = ogrenci.Tarih; 
tsList.Add(ts.tarih); 
tsList.Add(ogrenci.TaksitSayisi); 
tsList.Add((36000/Convert.ToInt32(ogrenci.TaksitSayisi)).ToString()); 

string odeme=(36000/Convert.ToInt32(ogrenci.TaksitSayisi)).ToString(); 
List<TaksitSaysi> lstTaksit = new List<TaksitSaysi>(); 
lstTaksit.Add(new TaksitSaysi() 
{ 
    taksitSayisi = ogrenci.TaksitSayisi, 
    tarih = ogrenci.Tarih, tutar = odeme 
}); 
return View("Index",lstTaksit); 

私が最初にtsListを試みるが、ラベルやdivの中のアイテムを表示することはできません。

今、私はlstTaksitを試してみます。私は再び私の考え方でいくつかの方法を試しましたが、どれもうまくいきません。

ラベルのテキストになりたい。私はif、for、foreachなどでコードを書いたときにそれを示していないことを再確認しました。例えば、私はdiv要素を作成し、その中のいくつかのテキストを書いて、それが

私の見解があるページに表示doesntの:

@model IEnumerable<TaksitSaysi> 
@if (Model != null) 
{ 
    foreach (var item in Model) 
    { 
     if (item != null) 
     { 

      **<div>deneme</div>** 
      <table id="Table" > 
      @for (int i=0;i<Convert.ToInt32(item.taksitSayisi) ;i++) 
      { 
       <text> <tr><td> @item.tutar </td></tr></text> 
      } 
      </table> 
      break; 
     } 
    } 
} 

答えて

0

をお使いのモデルでは、あなたのカスタムデータ型を作成することになるでしょう。ここで

は、あなたのアイデアを得るのを助けることが簡単な例です:

モデル:

public class MyType 
{ 
    public string Item1 { get; set; } 
    public string Item2 { get; set; } 
    public string Item3 { get; set; } 
} 

コントローラー:

public class HomeController : Controller 
{ 
    public ActionResult Index() 
    { 
     var myList = new List<MyType>(); 

     var customType1 = new MyType(); 
     customType1.Item1 = "Item 1a"; 
     customType1.Item2 = "Item 2a"; 
     customType1.Item3 = "Item 3a"; 
     myList.Add(customType1); 

     var customType2 = new MyType(); 
     customType2.Item1 = "Item 1b"; 
     customType2.Item2 = "Item 2b"; 
     customType2.Item3 = "Item 3b"; 
     myList.Add(customType2); 

     return View(myList); 
    } 
} 

ビュー:

@model IEnumerable<MvcApplication1.Models.MyType> 
<table> 
@foreach (var item in Model) { 
    <tr> 
     <td> 
      @item.Item1; 
      @item.Item2; 
      @item.Item3; 
     </td> 
    </tr> 
} 
</table> 
関連する問題