Модель MVC с несколькими свойствами HttpPostedFileBase - PullRequest
0 голосов
/ 12 октября 2011

Я использую следующую модель с моими действиями 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" />

Однако в последующем действии кажется, что свойства StartLedger и EndLedger заполнены одним и тем же значением (первый файл).

У кого-нибудь есть примеры обработки нескольких именованных полей загрузки файлов с помощью MVC3? Такое ощущение, что поддержка загрузки файлов была недостатком в ASP.Net MVC с версии 1.

---- РЕДАКТИРОВАТЬ (.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
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...