Asp.net mvc 3 UIHint不适用于IList?
我在视图模式下有一个属性:Asp.net mvc 3 UIHint不适用于IList?,asp.net-mvc-3,razor,data-annotations,partial-views,Asp.net Mvc 3,Razor,Data Annotations,Partial Views,我在视图模式下有一个属性: [UIHint("FileUpload")] public IList<string> Images { get; set; } 在文件夹Shared/EditorTemplates/FileUpload.cshtml <h3>Test</h3> 有什么不对劲吗? 你如何解决这个问题 如果我在我的Create.cshtml视图中手动添加下面的代码,它会工作 @Html.EditorFor(m => m.Images) 我
[UIHint("FileUpload")]
public IList<string> Images { get; set; }
在文件夹Shared/EditorTemplates/FileUpload.cshtml
<h3>Test</h3>
有什么不对劲吗?
你如何解决这个问题
如果我在我的Create.cshtml视图中手动添加下面的代码,它会工作
@Html.EditorFor(m => m.Images)
我不知道该怎么办。是的,
UIHint
不适用于列表。在相应的编辑器模板(~/Views/Shared/EditorTemplates/FileUpload.cshtml
)中需要一个循环。UIHint模板被传递给模型,在本例中,该模型是一个IList
@model-IList
@foreach(模型中的var项目)
{
...
}
但是为什么我要手动将代码@Html.EditorFor(m=>m.Images)
放在视图中,它会工作!?我认为问题不在于UIHint
,而在于@Html.EditorForModel()
否则代码@Html.EditorFor(m=>m.Images)
将不可用work@RidermandeSousaBarbosa,如果使用@Html.EditorForModel()
,则可以为给定视图模型(~/Views/Shared/EditorTemplates/MyViewModel.cshtml
)定义自定义编辑器模板,其中可以使用@Html.EditorFor(m=>m.Images)
。事实上,EditorForModel可能不会递归到子编辑器模板中。
[UIHint("FileUpload")]
public string Test { get; set; }
@Html.EditorFor(m => m.Images)
@model IList<string>
@foreach (var item in Model)
{
...
}