I am trying to go to the view using the specified batchId parameter enclosed in ViewModel, select the file to upload, return the downloaded file and save the file data with the associated BatchId value in the database.
When the form is submitted, I don’t know how to return the viewmodel and AddFileBase model to get the BatchId value.
I need a batchId value to associate it with the data that I store in the database.
I have the following action method in my controller, which allows me to add new clients to the specified group by loading and importing files:
public ActionResult AddCustomers(int batchId)
{
var viewModel = new AddCustomersViewModel() { BatchId = batchId,
return View(viewModel);
}
My opinion is strongly typed for this ViewModel:
Inherits="System.Web.Mvc.ViewPage<TestExcelImport.Areas.Admin.ViewModels.AddCustomersViewModel>
and has the following values for downloading the file:
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>AddCustomers Batch ID : <%:Model.BatchId %></h2>
<form action="/Admin/Dashboard/AddCustomers" enctype="multipart/form-data" method="post">
<input type="file" id="SourceFile" name="SourceFile" />
<br />
<input type="submit" value="Send" name="btnUpload" id="Submit1" />
</form>
</asp:Content>
My HttpPost action method is defined as:
[HttpPost]
public ActionResult AddCustomers(HttpPostedFileBase SourceFile)
{
int fileLength = SourceFile.ContentLength;
return RedirectToAction("Index");
}
AddCustomersViewModel HttpPost, . / , , BatchId .
- , ?