有没有办法将Html.EditorFor与HttpPostedFileBase对象的通用列表一起使用?
我正在建立一个网站,其中一个网页可以附加最多3个文件。我的代码目前看起来像这样 -
型号
public IEnumerable<HttpPostedFileBase> Attachments { get; set; }
查看
<div>
@{
for (int i = 0; i < 3; i++)
{
<input type="file" name="Attachments[@i]" />
}
}
</div>
有没有办法用<input type="file" name="Attachments[@i]" />
语句替换EditorFor
?
答案 0 :(得分:0)
你可以这样做
<div>
@{
for (int i = 0; i < 3; i++)
{
@Html.Editor("Attachments["+ i +"]", new { htmlAttributes = new { type = "file" }})
}
}
</div>
或
<div>
@Html.Editor("Attachments", new { htmlAttributes = new { type = "file" }})
@Html.Editor("Attachments", new { htmlAttributes = new { type = "file" }})
@Html.Editor("Attachments", new { htmlAttributes = new { type = "file" }})
</div>
您也可以使用TextBox
@Html.TextBox("Attachments",new { type = "file" })