How can i upload a file with additional data in ASP.NET MVC? This is what I have so far:
@using (Html.BeginForm("CreateSiteLogo", "SiteSettings", FormMethod.Post))
{
@Html.TextBoxFor(a=>a.SiteNameKey)
<input type="file" name="logo" id="logo" />
<input type="submit" />
}
Action:
[HttpPost]
public ActionResult CreateSiteLogo(SiteSettingsAPIModel siteSetting)
{
// Handle model
}
Model:
public class SiteSettingsAPIModel
{
public int Id { get; set; }
public string SiteNameKey { get; set; }
public byte[] SiteLogo { get; set; }
public string ImageFormat { get; set; }
}
I can only get the value of the input[text] but not the input[file]. I tried using Request.Files[0]
but I'm always getting null.