Sorry I am quite new in ASP.NET MVC and I have this piece of code in the Home
view folder (file Index.cshtml
):
@{
ViewBag.Title = "Home Page";
}
<div class="row">
<div class="col-md-4">
<h2>Select file</h2>
<p>
<input id="File1" type="file" />
</p>
<p><a class="btn btn-default" href="https://go.microsoft.com/fwlink/?LinkId=301865">Learn more »</a></p>
</div>
<div class="col-md-4">
<h2>Upload to SQL Server</h2>
<input type="button" title="Upload to SQL Server" value="Upload to SQL Server" onclick="location.href='@Url.Action("Upload2SS", "SystemLogs")'" />
</div>
</div>
When I click the "Upload to SQL Server" button, I simply want to pass the File1
value to the controller action:
public RedirectToRouteResult Upload2SS(FormCollection form)
{
string filePath = form["File1"].ToString();
var data = GetDataTabletFromCSVFile(filePath);
return RedirectToAction("Index");
}
However, I keep on getting a System.NullReferenceException
for the filePath variable; can anyone tell me what I am missing please?