Reputation: 7977
I have two editor templates:
UploadFiles.cshtml:
@model HttpPostedFileBase[]
@Html.EditorFor(m => Model, "UploadFile", new { multiple = true })
UploadFile.cshtml:
@model HttpPostedFileBase
@Html.TextBox("", Model, new { type = "file", multiple = Convert.ToBoolean(ViewBag.Multiple) ? "multiple" : "" })
<!-- Additional code here i don't wish to repeat in both controls -->
Notice how UploadFiles.cshtml template accepts an array and then calls the UploadFile.cshtml template and passes in multiple = true via the view data.
The problem i have is if i say:
@Html.EditorFor(m => Model.Files, "UploadFiles")
It doesn't render anything.
However if i say:
@Html.EditorFor(m => Model.File, "UploadFile")
It renders correctly.
I'd appreciate if someone could show me how this can be achieved.
Thanks
Upvotes: 0
Views: 1800
Reputation: 5187
In UploadFiles.cshtml, you're passing Model
, which is an array, to UploadFile.cshtml, which does not take an array. Did you mean to wrap that line in a foreach?
foreach (var file in Model)
{
@Html.EditorFor(x => file, "UploadFile", new { multiple = true })
}
Upvotes: 1