It turns out that I'm trying to make a post from a posted file from the asp view to the controller but it turns out that the file arrives null simply is not sent nose that may be happening the error is this: Additional information: Object reference not set to an instance of an object. aspx code
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" AutoEventWireup="true" CodeBehind="Mantenedor.aspx.cs" Inherits="MVEL.Views.Mantenedor.Mantenedor" %>
<div class="col-lg-12 col-sm-12">
<div class="well row" style="margin-top: 25px; padding: 0px; margin-bottom: 0px;">
<h1 style="text-align: center; font-family: Univers Bold; font-size: 30px; margin-top: 10px; color: #073492; padding-right: 100px; border-right-width: 31px;">Mantenedor</h1>
<div style="padding-left: 195px; border-left-width: 1px;">
<select id="ddlUploads" name="ddlUploads" class="auto-style2" style="border: 3px solid #ddd; padding-left: 0px; padding-right: 0px; margin-left: 283px; margin-right: 116px;">
<option value="0">--seleccione--</option>
<option value="1">Factor de Penalización</option>
<option value="2">Movimientos Centrales</option>
<option value="3">Costo Marginal del Mínimo Técnico</option>
</select>
</div>
</div>
</div>
</div>
<br />
<br />
<div class="input-group" style="margin-top: 2%">
</div>
<br />
<br />
<div id="valor1">
Factor de Penalización
<%using (Html.BeginForm("Mantenedor", "Mantenedor", FormMethod.Post, new { enctype = "multipart/form-data" }))
{%><input type="file" value="0" id="file" name="file" required="">
<input type="submit" value="Subir PO.xlsx" />
<%} %>
<br />
<br />
</div>
</asp:Content>
Code c # of my controller
public ActionResult Mantenedor()
{
return View("~/Views/Mantenedor/Mantenedor.aspx");
}
[HttpPost]
public ActionResult Mantenedor(HttpPostedFileBase file)//File llega null
{
string filename = Guid.NewGuid() + Path.GetExtension(file.FileName);// Acá ocurre el error
string filepath = "/excelFolder/" + filename;
file.SaveAs(Path.Combine(Server.MapPath("/excelFolder/"), filename));
InsertExceldata(filepath, filename);
return View("~/Views/Mantenedor/Mantenedor.aspx");
}