如何在IEnumerable上使用HTML帮助器? [英] How to use HTML helpers on an IEnumerable?
本文介绍了如何在IEnumerable上使用HTML帮助器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下IEnumerable
I have the following IEnumerable
public class AuditDetailsViewModel
{
public string CustAddress { get; set; }
public IEnumerable<DefectDetailsViewModel> DefectDetails { get; set; }
}
public class DefectDetailsViewModel
{
public string Description { get; set; }
public string Comments { get; set; }
}
在剃须刀视图中,如何使用HTML帮助程序进行枚举?如果是列表,我可以执行以下操作
In my razor view how I can enumerate over this using the Html helpers? If it was a list I could do the something like the following
@model AIS.Web.Areas.Inspector.ViewModel.AuditDetailsViewModel
@for (int i = 0; i < Model.DefectDetails.Count(); i++)
{
@Html.TextBoxFor(m => m.DefectDetails[i].Description)
}
但是如果viewmodel是IEnumerable怎么办?
but how can I do that if the viewmodel is an IEnumerable?
推荐答案
在遍历一个可枚举的对象时,我使用了foreach
I use a foreach when looping through an ienumerable
foreach(var temp in Model.DefectDetails){
@Html.TextBoxFor(x => temp.Description)
}
希望这会有所帮助
这篇关于如何在IEnumerable上使用HTML帮助器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文