如何在MVC3中显示数组?

时间:2012-08-31 12:10:27

标签: asp.net-mvc-3

朋友们,我从Web服务获取数据,因此我无法使用Html.DisplayFor(model => model.item),如何在数组中显示数据。这是我的代码:

@using icerik.TahakkukServices


@{
    ViewBag.Title = "Deneme";
    Layout = "~/Views/Shared/_Layout5.cshtml";
}


@{
    TahakkukServicesClient client = new TahakkukServicesClient();
    client.ClientCredentials.UserName.UserName = "service_test";
    client.ClientCredentials.UserName.Password = "";
    client.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None;
    MakbuzList[] liste = client.GetMakbuzListe(2);

}

 @foreach (var item in liste)
 {

Html.DisplayFor(item.Adi)
                }

2 个答案:

答案 0 :(得分:1)

@model icerik.TahakkukServices。添加你的表名

@{ 
    ViewBag.Title = "Deneme"; 
    Layout = "~/Views/Shared/_Layout5.cshtml"; 
} 


@{ 
    TahakkukServicesClient client = new TahakkukServicesClient(); 
    client.ClientCredentials.UserName.UserName = "service_test"; 
    client.ClientCredentials.UserName.Password = ""; 
    client.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; 
    MakbuzList[] liste = client.GetMakbuzListe(2); 

} 

 @foreach (var item in liste) 
 { 

Html.DisplayFor(model=>model.) add your column name
                } 

答案 1 :(得分:0)

好吧,我知道如何使用您的服务提供型号名称,如下所示

@model icerik.TahakkukServices.Borc

所以你可以使用Html.DisplayFor