I'm trying to upload multiple excel files.
However I am getting error messages as below: "Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NullReferenceException: Object reference not set to an instance of an object."
Below is the part of "Index.cshtml" where I upload files:
@using (Html.BeginForm("Index", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<input type="file" name="postedFile1" id="file1" />
<input type="file" name="postedFile2" id="file2" />
<input type="submit" value="Upload" />
}
Below is a part of my "HomeController.cs". The foreach
part is being highlighted so I assume that postedFile
is not getting the uploaded files.
[HttpPost]
public ActionResult Index(IEnumerable<HttpPostedFileBase> postedFiles)
{
// Upload file on Server
string path = Server.MapPath("~/Uploads/");
string filePath = string.Empty;
string extension = string.Empty;
var ExcelDatas = new List<DataSet>();
foreach (HttpPostedFileBase postedFile in postedFiles)
{
if (postedFile != null)
{
How can I fix this?