Pergunta

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

Foi útil?

Solução

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 })
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top