My view has two Forms...
@using (Html.BeginForm("Upload", "CSV",
null, FormMethod.Post, new { enctype = "multipart/form-data" }))
{
--file picker--
<div class="form-group">
<input type="submit" value="Upload" class="btn btn-default" />
</div>
}
@using (Html.BeginForm("Add", "CSV",
null, FormMethod.Post, new { enctype = "multipart/form-data" }))
{
--- other functionality--
<div class="form-group">
<input type="submit" value="Add" id="ShortURL" class="btn btn-default" />
</div>
}
This view is linked to a model with an ID field.
By the time I get to this view I am passing along the ID from another view which I need to perform the "Add" method. And if I do the "Add" first it works fine.
However, if I do the "Upload" first then I lose the ID when it gets back to the controller. How can I store the ID after going to the Upload method first and then the Add method?
Here are the relevant controller methods...
[HttpPost]
public ActionResult Upload(HttpPostedFileBase upload)
{
if (ModelState.IsValid)
{
if (TempData["Model"] != null)
{
var data = TempData["Model"] as CSV;
CSV UploadData = data;
UploadData.ID = UploadData.Upload(upload, data.ID);
return View("CSV", UploadData);
}
}
return View("CSV");
}
public ActionResult CSV(CSV Model)
{
TempData["Model"] = Model;
return View("CSV",Model);
}
[HttpPost]
public ActionResult Add(CSV Model)
{
//need to use the ID field in here
}