0

resulta que estoy tratando de hacer un post de un posted file desde la vista asp al controlador pero resulta que el archivo llega null simplemente no se envia nose que puede estar pasando el error es este: Additional information: Object reference not set to an instance of an object. codigo aspx

<%@ 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>

Codigo c# de mi controlador

 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");
    }
3

0

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

Examina otras preguntas con la etiqueta o formula tu propia pregunta.