I have a page with model that i want to send to controller with additional files (files are not in model). So far i'm submitting everything OK but since i'm doing it in partial i want to send model and files to controller and stay on the same page. I would also like to get response to page if upload is successful so i can handle form elements. This is what i have:
View
@model Test.Controllers.HomeController.MyClass
@{
ViewBag.Title = "Index";
}
@using (Html.BeginForm("Save", "Home", FormMethod.Post, new { role = "form", enctype = "multipart/form-data" }))
{
@Html.AntiForgeryToken()
@Html.TextBoxFor(m=>m.Number)
<input id="file" name="file" type="file" multiple>
<button class="btn btn-primary center-block" id="saveButton">
Save <span class="glyphicon glyphicon-ok" style="color: white;" type="submit"></span>
</button>
}
Controller
// GET: Home
public ActionResult Index()
{
return View();
}
[HttpPost]
[ValidateAntiForgeryToken]
public virtual JsonResult Save (MyClass model, List<HttpPostedFileBase> file)
{
return Json(true);
}
public class MyClass
{
public int Number { get; set; }
}
I want to get response (Json or something else) when save is complete so i can reload some data grids and such. If i try to send form with ajax (form.serialize) my files are always null. Any help is appreciated