So I've read several guides on this and I'm still having a problem. I'm using ASP.NET MVC 4 Razor.
Here's what I have so far:
Controller
public class FormsController : Controller
{
[HttpPost]
[ValidateAntiForgeryToken]
[AllowAnonymous]
public ActionResult TechProjectPlan(IEnumerable<HttpPostedFileBase> files, MvcApplication1.Models.TechProjectPlanModel model, string returnUrl)
{
//stuff here
}
}
This form includes a lot of different fields, not just the files, so I have the model here as well. The request gets to the controller and action just fine, but "files" is always "Count = 0", just empty.
Here's the View stuff:
@using (Html.BeginForm("SubmitForm", "Forms", new { enctype = @"multipart/form-data" }))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<h3>Project Information</h3>
<fieldset>
<legend>Project Information</legend>
<ol style="display:block; *display:inline; *zoom:1;">
<li style="float:left;">
@Html.LabelFor(m => m.Item1)
@Html.TextBoxFor(m => m.Item1, new { @class = "CostItem" })
</li>
<li style="float:left;">
@Html.LabelFor(m => m.Quantity1)
@Html.TextBoxFor(m => m.Quantity1, new { @class = "CostQuantity" })
<span> $</span>
</li>
<li style="float:left;">
@Html.LabelFor(m => m.PerUnitCost1)
@Html.TextBoxFor(m => m.PerUnitCost1, new { @class = "CostPerUnitCost" })
<span> $</span>
</li>
<li style="float:left;">
@Html.LabelFor(m => m.Extension1)
@Html.TextBoxFor(m => m.Extension1, new { @class = "CostExtension" })
</li>
<li style="float:left;">
@Html.LabelFor(m => m.Attachment1)
<input type="file" value="Upload" name="file" id="upload1" style="padding: 5px;" />
</li>
</ol>
<ol style="display:block; *display:inline; *zoom:1;">
<li style="float:left;">
@Html.TextBoxFor(m => m.Item2, new { @class = "CostItem" })
</li>
<li style="float:left;">
@Html.TextBoxFor(m => m.Quantity2, new { @class = "CostQuantity" })
<span> $</span>
</li>
<li style="float:left;">
@Html.TextBoxFor(m => m.PerUnitCost2, new { @class = "CostPerUnitCost" })
<span> $</span>
</li>
<li style="float:left;">
@Html.TextBoxFor(m => m.Extension2, new { @class = "CostExtension" })
</li>
<li style="float:left;">
<input type="file" value="Upload" name="files" id="upload2" style="padding: 5px;" />
</li>
</ol>
</fieldset>
<input type="submit" value="Submit"/>
}
As you can see, the input types file all have the name "files", matching the parameter in the ActionResult on the controller, and it's my understanding that the compiler is supposed to implicitly match these.
Thanks for the help!