0

Tengo este formulario:

@using (Html.BeginForm("Create", "Equipments", FormMethod.Post, new { }))
                    {
                @Html.AntiForgeryToken()
                @Html.HiddenFor(model => model.Parts)
                @Html.HiddenFor(model => model.Toners)
                <div class="box-body">
                    <div class="form-group">
                        @Html.LabelFor(model => model.SerialNumber)
                        @Html.EditorFor(model => model.SerialNumber, new { htmlAttributes = new { @class = "form-control", placeholder = "Entre serial del equipo", required = "required" } })
                    </div>

                    <div class="form-group">
                        @Html.LabelFor(model => model.TypeMachine)
                        @Html.EnumDropDownListFor(model => model.TypeMachine, "Seleccione...", htmlAttributes: new { @class = "form-control", required = "required" })
                    </div>

                    <div class="form-group">
                        @Html.LabelFor(model => model.Model)
                        @Html.EditorFor(model => model.Model, new { htmlAttributes = new { @class = "form-control", placeholder = "Entre modelo del equipo", required = "required" } })
                    </div>

                    <div class="form-group">
                        @Html.LabelFor(model => model.Location)
                        @Html.EditorFor(model => model.Location, new { htmlAttributes = new { @class = "form-control", placeholder = "Entre ubicación del equipo", required = "required" } })
                    </div>

                    <div class="form-group">
                        @Html.LabelFor(model => model.IP)
                        <div class="input-group">
                            <div class="input-group-addon">
                                <i class="fa fa-desktop"></i>
                            </div>
                            <input class="form-control text-box single-line" data-val="true" data-val-length="Debe ser una dirección IP válida" data-val-length-max="12" data-val-length-min="4" data-val-regex="Debe ser una dirección IP válida" data-val-regex-pattern="^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$" data-val-required="Dirección IP requerida" id="IP" name="IP" placeholder="172.239.17.192" type="text" required>
                        </div>
                    </div>

                    <div class="form-group">
                        @Html.LabelFor(model => model.PMInterval)
                        @Html.EditorFor(model => model.PMInterval, new { htmlAttributes = new { @class = "form-control", placeholder = "60,000", required = "required" } })
                    </div>

                    <div class="form-group">
                        @Html.LabelFor(model => model.CounterBnWCopies)
                        @Html.EditorFor(model => model.CounterBnWCopies, new { htmlAttributes = new { @class = "form-control", placeholder = "60,000", required = "required" } })
                    </div>

                    <div class="form-group">
                        @Html.LabelFor(model => model.CounterBnWPrints)
                        @Html.EditorFor(model => model.CounterBnWPrints, new { htmlAttributes = new { @class = "form-control", placeholder = "60,000", required = "required" } })
                    </div>

                    <div class="form-group">
                        @Html.LabelFor(model => model.CounterColorCopies)
                        @Html.EditorFor(model => model.CounterColorCopies, new { htmlAttributes = new { @class = "form-control", placeholder = "60,000", required = "required" } })
                    </div>

                    <div class="form-group">
                        @Html.LabelFor(model => model.CounterColorPrints)
                        @Html.EditorFor(model => model.CounterColorPrints, new { htmlAttributes = new { @class = "form-control", placeholder = "60,000", required = "required" } })
                    </div>

                    <div class="form-group ">
                        <div class="checkbox">
                            <input type="checkbox" name="IsActive" id="IsActive" data-val="true" data-val-required="El campo Disponible / Activo es obligatorio." style="position: absolute; opacity: 0;">
                            <label for="IsActive"> Disponible / Activo</label>
                        </div>
                        <p class="help-block">Este Equipo estará disponible?</p>
                    </div>
                </div>
                <div class="box-footer">
                    <input type="submit" class="btn btn-primary pull-right" value="Crear">
                </div>
            }

y tambien, este elemento:

@Html.DropDownList("SearchToners", ViewBag.SearchToners as IEnumerable<SelectListItem>, "Buscar Toners para modelo", new { @class = "form-control selectpicker", style = "width:270px" })

Metodo en el controller

    public ActionResult Create()
    {
        ViewBag.BreadCrumb = new List<string> { "Stock", "Equipos", "Crear" };
        ViewBag.SearchToners = new SelectList(EquipmentService.ToList().ToList(), "Id", "Model");
        return View();
    }

El DropDownList esta fuera y muy lejos del Form. No se por que me da ese error si ni siquiera esta dentro de request que se enviara al controlador

0

1 respuesta 1

0

[SOLUCIONADO]

En el método post estoy retornando la vista sin mas. Entonces ASP, inteligentemente, lee la vista a la cual sera direccionada la respuesta del servidor.

Cuando ASP intentaba dibujar el DropDownList no encontraba el ViewBag.SearchToner. No existe, por que nunca se creo, en esa respuesta del servidor.

Metodos:

    [HttpGet]
    public ActionResult Create()
    {
        ViewBag.SearchToners = new SelectList(EquipmentService.ToList().ToList(), "Id", "Model");
        return View();
    }

Antes de la solucion:

    [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult Create(string test)
    {
        return View();
    }

Después de la solución:

    [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult Create(string test)
    {
        ViewBag.SearchToners = new SelectList(EquipmentService.ToList().ToList(), "Id", "Model");
        return View();
    }

Tu Respuesta

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

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.