I have form with file upload on default 'Index' view that calls action ('FileUpload') from the same controller ('Admin' in this example):
@using (Html.BeginForm("FileUpload", "Admin", FormMethod.Post, htmlAttributes: new { enctype = "multipart/form-data" }))
{
<label for="articleFile" class="control-label">Upload article</label>
<input id="articleFile" name="articleFile" type="file" accept=".txt" />
<button type="submit">Upload</button>
}
When I navigate to this view URL looks like:
Inside FileUpload action I do upload logic, create model for 'Index' view, set some values in model (e.g. upload status message) and return ViewResult:
[HttpPost]
public ActionResult FileUpload(HttpPostedFileBase articleFile)
{
IndexModel model = new IndexModel();
// file upload logic here
model.FileUploadMessage = "message";
return View("Index", model);
}
It all works fine, file is uploaded and message is displayed but URL in browser changes to:
So my question is: Is it possible to prevent it and make URL stay the same after form submit done that way, when ViewResult with action name Index and model is returned?
I know that I can use jQuery plugin for ajax async file upload or use RedirectToAction as result but then I am not be able to pass model, just route values.