我在get / post操作中使用以下模型。
Public Class AuthorEditQuestionViewModel
<Required()>
<Display(Name:="Question Title")>
Public Property Title As String
<Display(Name:="Start Ledger")>
Public Property StartLedger As HttpPostedFileBase
Public Property StartLedgerUrl As String
<Display(Name:="End Ledger")>
Public Property EndLedger As HttpPostedFileBase
Public Property EndLedgerUrl As String
<Required()>
<Display(Name:="Introduction/Instructions")>
Public Property IntroductionHtml As String
End Class
分类帐字段的html如下所示。
<input type="file" id="StartLedger" name="StartLedger" />
<input type="file" id="EndLedger" name="EndLedger" />
但是,在post操作中,似乎StartLedger和EndLedger属性似乎都填充了相同的值(第一个文件)。
有没有人有任何使用MVC3处理多个命名文件上传字段的示例?从版本1开始,支持文件上传确实是ASP.Net MVC的一个缺点。
----编辑(下面的.vbhtml)
@Using Html.BeginForm("EditQuestion", "Author", Nothing, FormMethod.Post, New With {.enctype = "multipart/form-data"})
@Html.ValidationSummary("Please correct the following issues.")
@<table class="form">
<tr>
<td class="label">@Html.LabelFor(Function(m) m.Title)</td>
<td class="input">
@Html.TextBoxFor(Function(m) m.Title)
</td>
</tr>
<tr>
<td class="label">@Html.LabelFor(Function(m) m.StartLedger)</td>
<td class="input">
<input type="file" id="StartLedger" name="StartLedger" />
@If Not String.IsNullOrWhiteSpace(Model.StartLedgerUrl) Then
@<a href="@Model.StartLedgerUrl">Download</a>
End If
</td>
</tr>
<tr>
<td class="label">@Html.LabelFor(Function(m) m.EndLedger)</td>
<td class="input">
<input type="file" id="EndLedger" name="EndLedger" />
@If Not String.IsNullOrWhiteSpace(Model.EndLedgerUrl) Then
@<a href="@Model.EndLedgerUrl">Download</a>
End If
</td>
</tr>
<tr>
<td class="label" colspan="2">@Html.LabelFor(Function(m) m.IntroductionHtml)</td>
</tr>
<tr>
<td class="input" colspan="2">@Html.TextAreaFor(Function(m) m.IntroductionHtml, 10, 80, Nothing)</td>
</tr>
<tr>
<td class="buttons" colspan="2">
<button class="action" data-action="@Url.Action("Index")">Cancel</button>
<button>Save</button>
</td>
</tr>
</table>
End Using
行动的签名如下......
Function EditQuestion(id As Guid?, model As AuthorEditQuestionViewModel) As ActionResult