Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 3 UIHint不适用于IList?_Asp.net Mvc 3_Razor_Data Annotations_Partial Views - Fatal编程技术网

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)
{
    ...
}