0

大家好,我正在尝试从控制器返回一个数组以查看。这是我的控制器:

public ActionResult Index()

        {
            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);
            return View(liste);
        }

    }
}

那么如何在视图中显示数组的值呢?

4

2 回答 2

1

MakbuzList[]“是”一个IEnumerable<MakbuzList>(注意:现在,通用列表/集合通常比数组更受欢迎)

所以你可以像这样强烈地输入你的视图

@model IEnumerable<MakbuzList>

并显示这样的值

@if (Model.Any()) {
  foreach (var makbuz in Model) {
     @Html.DisplayFor(x => makbuz.Property1)
  }
}
于 2012-09-05T15:10:00.823 回答
0

假设视图已经配置了

@model IList<MakbuzList>

然后你可以简单地做

@for (var i = 0; i < Model.Count; ++i) {
    @Html.DisplayFor(m => m[i]);
}
于 2012-09-05T15:11:03.910 回答