Note that there are some explanatory texts on larger screens.

plurals
  1. POMVC Model with multiple HttpPostedFileBase properties
    primarykey
    data
    text
    <p>I'm using the following model with my get/post actions.</p> <pre><code>Public Class AuthorEditQuestionViewModel &lt;Required()&gt; &lt;Display(Name:="Question Title")&gt; Public Property Title As String &lt;Display(Name:="Start Ledger")&gt; Public Property StartLedger As HttpPostedFileBase Public Property StartLedgerUrl As String &lt;Display(Name:="End Ledger")&gt; Public Property EndLedger As HttpPostedFileBase Public Property EndLedgerUrl As String &lt;Required()&gt; &lt;Display(Name:="Introduction/Instructions")&gt; Public Property IntroductionHtml As String End Class</code></pre> <p>The html for the ledger fields is as follows.</p> <pre><code>&lt;input type="file" id="StartLedger" name="StartLedger" /&gt; &lt;input type="file" id="EndLedger" name="EndLedger" /&gt;</code></pre> <p>However, in the post action, it seems that both the StartLedger and EndLedger properties seem to be populated with the same value (the first file).</p> <p>Does anyone have any examples of handling multiple named file upload fields with MVC3? It really feels like supporting file uploads well has been a shortcoming in ASP.Net MVC since version 1.</p> <p>---- EDIT (.vbhtml below)</p> <pre><code>@Using Html.BeginForm("EditQuestion", "Author", Nothing, FormMethod.Post, New With {.enctype = "multipart/form-data"}) @Html.ValidationSummary("Please correct the following issues.") @&lt;table class="form"&gt; &lt;tr&gt; &lt;td class="label"&gt;@Html.LabelFor(Function(m) m.Title)&lt;/td&gt; &lt;td class="input"&gt; @Html.TextBoxFor(Function(m) m.Title) &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class="label"&gt;@Html.LabelFor(Function(m) m.StartLedger)&lt;/td&gt; &lt;td class="input"&gt; &lt;input type="file" id="StartLedger" name="StartLedger" /&gt; @If Not String.IsNullOrWhiteSpace(Model.StartLedgerUrl) Then @&lt;a href="@Model.StartLedgerUrl"&gt;Download&lt;/a&gt; End If &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class="label"&gt;@Html.LabelFor(Function(m) m.EndLedger)&lt;/td&gt; &lt;td class="input"&gt; &lt;input type="file" id="EndLedger" name="EndLedger" /&gt; @If Not String.IsNullOrWhiteSpace(Model.EndLedgerUrl) Then @&lt;a href="@Model.EndLedgerUrl"&gt;Download&lt;/a&gt; End If &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class="label" colspan="2"&gt;@Html.LabelFor(Function(m) m.IntroductionHtml)&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class="input" colspan="2"&gt;@Html.TextAreaFor(Function(m) m.IntroductionHtml, 10, 80, Nothing)&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class="buttons" colspan="2"&gt; &lt;button class="action" data-action="@Url.Action("Index")"&gt;Cancel&lt;/button&gt; &lt;button&gt;Save&lt;/button&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; End Using</code></pre> <p>The signature for the action is as follows...</p> <pre><code>Function EditQuestion(id As Guid?, model As AuthorEditQuestionViewModel) As ActionResult</code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload