I need to call a MVC controller function and return back to same view without refreshing the view.
The upload function allows multiple files but I would like to restrict it to 10 files.
Current scenario
I have an upload function on a razor page. The code below calls a "UploadFiles" function.
I would like to return to same page without refreshing it.
@using (Html.BeginForm("UploadFiles", "Mycontroller", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
@Html.AntiForgeryToken()
@Html.LabelFor(model => model.files, htmlAttributes: new { @class = "control-label col-md-2" })
@Html.TextBoxFor(model => model.files, "", new { @type = "file", @multiple = "multiple" })
@Html.ValidationMessageFor(model => model.files, "", new { @class = "text-danger" })
<div class="form-group">
<input type="submit" value="Upload" class="btn btn-primary" />
</div>
}
The controller code is as follows
[HttpPost]
public ActionResult UploadFiles(HttpPostedFileBase[] files)
{
//code inputstream file to bytes
return View();
}
I also tried using but it gets redirecting to a different page.
public void UploadFiles(HttpPostedFileBase[] files)
{
//code inputstream file to bytes
return View();
}