0

lo que quiero hacer es que el mensaje emergente me aparezca en la vista de create antes de que me redireccione al index y que cuando le de click a aceptar del mensaje me redireccione a index y pues no comprendo el porque no puedo hacer con algunos ejemplos lo intentado pero no me sale

Este es mi get del controlador (create)

    // GET: Reflectores/Create
    public ActionResult Create()
    {
        ViewBag.IdTipo = new SelectList(db.TiposdeReflectores, "IdTipo", "TipodeReflector");
        ViewBag.IdTurno = new SelectList(db.TurnodelOperadors, "IdTurno", "Turno");
        return View();
    }

el controlador del mismo(create)

  [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult Create([Bind(Include = "IdReflector,Fecha,Operador,IdTurno,NumTO,NumParte,IdTipo,NumSerie,ClaseRMS,RMSValor,ValidaciondeRMS,EmpacadoMPS,Comentario,contador,contadorLT")] Reflector reflector)
    {
        reflector.Fecha = Convert.ToDateTime(DateTime.Now.Date.ToShortDateString());
        //  reflector.Fecha = DateTime.Now.Date.ToShortDateString();
        if (ModelState.IsValid)
        {
            db.Reflectors.Add(reflector);
            db.SaveChanges();

aquie es donde me redirecciona al index pero quiero que primero me salga el mensaje

            return RedirectToAction("Index");
        }

        ViewBag.IdTipo = new SelectList(db.TiposdeReflectores, "IdTipo", "TipodeReflector", reflector.IdTipo);
        ViewBag.IdTurno = new SelectList(db.TurnodelOperadors, "IdTurno", "Turno", reflector.IdTurno);

aqui use el mensaje de viewbag pero no es lo que necesito

        //ViewBag.Crotolamo = "No puede ser el mismo inspecto IPQC y OBA";

        return View(reflector);
    }

vista create

  @model Docuemto_de_reporte_de_excel.Models.Reflector

@{
    /**/

    ViewBag.Title = "Create";
}



<h2>Registro de Reflector</h2>

<script>

    function habilitar() {
        var chk = document.getElementById('ValidacionDeRMS');
        var txt = document.getElementById('validacion');
        if (chk.checked) {
            txt.value = 'N/A';

            txt.disabled = 'disabled';
        } else {
            txt.disabled = '';
            txt.value = '';

        }
    }
    function habilitar2() {
        var chk = document.getElementById('ValidacionDeCM');
        var txt = document.getElementById('validacion2');
        if (chk.checked) {
            txt.value = 'N/A';

            txt.disabled = 'disabled';
        } else {
            txt.disabled = '';
            txt.value = '';

        }
    }

</script>


@using (Html.BeginForm())

{



   @Html.AntiForgeryToken()

<div class="form-horizontal" id="mymodal">
    <h4>Reflector</h4>
    @if (TempData["Success"] != null)
    {
        <p class="alert alert-success" id="successMessage">@TempData["Success"]</p>
    }
    <hr />
    @Html.ValidationSummary(true, "", new { @class = "text-danger" })


    <div class="form-group">
        @Html.LabelFor(model => model.Operador, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.Operador, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.Operador, "", new { @class = "text-danger" })
        </div>
    </div>

    <div class="form-group">
        @Html.LabelFor(model => model.IdTurno, "IdTurno", htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.DropDownList("IdTurno", null, htmlAttributes: new { @class = "form-control" })
            @Html.ValidationMessageFor(model => model.IdTurno, "", new { @class = "text-danger" })
        </div>
    </div>

    <div class="form-group">
        @Html.LabelFor(model => model.NumTO, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.NumTO, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.NumTO, "", new { @class = "text-danger" })
        </div>
    </div>

    <div class="form-group">
        @Html.LabelFor(model => model.NumParte, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.NumParte, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.NumParte, "", new { @class = "text-danger" })
        </div>
    </div>

    <div class="form-group">
        @Html.LabelFor(model => model.contadorLT, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.contadorLT, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.contadorLT, "", new { @class = "text-danger" })
        </div>
    </div>

    <div class="form-group">
        @Html.LabelFor(model => model.IdTipo, "IdTipo", htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.DropDownList("IdTipo", null, htmlAttributes: new { @class = "form-control" })
            @Html.ValidationMessageFor(model => model.IdTipo, "", new { @class = "text-danger" })
        </div>
    </div>


    <div class="form-group">
        @Html.LabelFor(model => model.NumSerie, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.NumSerie, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.NumSerie, "", new { @class = "text-danger" })
        </div>
    </div>


    <div class="from-gruop" align="left">
        <div>
            &emsp; &emsp;&emsp;<label class="control-label col-md-2">Selector de Numero de Clase:</label>&nbsp; &nbsp;
        </div>

        @*<select id="selecionaNUM" class="form-control" onchange="select();" name="selectclase">
                    <option value="1">1</option>
                    <option value="2">2</option>
                    <option value="3">3</option>


                </select>
            </div>*@



        <div class="form-group">
            @Html.LabelFor(model => model.ClaseRMS, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">


                <label class="btn btn-success">
                    A
                    @Html.RadioButtonFor(model => model.ClaseRMS, "A", new { htmlAttributes = new { @class = "form-control", @id = "clasea" } })

                </label>
                <label class="btn btn-danger">
                    B
                    @Html.RadioButtonFor(model => model.ClaseRMS, "B", new { htmlAttributes = new { @class = "form-control" } })

                </label>
                <label class="btn btn-primary">
                    C
                    @Html.RadioButtonFor(model => model.ClaseRMS, "C", new { htmlAttributes = new { @class = "form-control" } })
                </label>

                @Html.ValidationMessageFor(model => model.ClaseRMS, "", new { @class = "text-danger" })
            </div>
        </div>
        <div class="from-gruop" align="left">

            &emsp; &emsp;&emsp;<label>No Aplica En el RMS Valor:</label>&nbsp; &nbsp; <input id="ValidacionDeRMS" type="checkbox" onchange="habilitar();" />

        </div>
        <div class="form-group">
            @Html.LabelFor(model => model.RMSValor, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.RMSValor, new { htmlAttributes = new { @class = "form-control", @id = "validacion" } })
                @Html.ValidationMessageFor(model => model.RMSValor, "", new { @class = "text-danger" })
            </div>
        </div>


        <div class="form-group">
            @Html.LabelFor(model => model.ValidaciondeRMS, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.ValidaciondeRMS, new { htmlAttributes = new { @class = "form-control", @id = "mega" } })
                @Html.ValidationMessageFor(model => model.ValidaciondeRMS, "", new { @class = "text-danger" })
            </div>
        </div>




        <div class="form-group">
            @Html.LabelFor(model => model.EmpacadoMPS, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.EmpacadoMPS, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.EmpacadoMPS, "", new { @class = "text-danger" })
            </div>
        </div>
        <div class="from-gruop" align="left">

            &emsp; &emsp;&emsp;<label>No Aplica Comentario:</label>&nbsp; &nbsp; <input id="ValidacionDeCM" type="checkbox" onchange="habilitar2();" />

        </div>
        <div class="form-group">
            @Html.LabelFor(model => model.Comentario, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Comentario, new { htmlAttributes = new { @class = "form-control", @id = "validacion2" } })
                @Html.ValidationMessageFor(model => model.Comentario, "", new { @class = "text-danger" })
            </div>
        </div>
        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <div class="glyphicon glyphicon-plus">

aqui este el buton que me redirecciona al create que esl input value ="Terminar"

                    <input type="submit" name="response" value="Terminar" class="btn btn-success" />

                </div>
                <br />
                <br />
                @*<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">
                        Launch demo modal
                    </button>*@
                @Html.ActionLink(" Regresar A la lista", "Index", null, new { @class = "btn btn-warning glyphicon glyphicon-arrow-left" })

                @*<button class="btn-danger eliminar" data-id="@Model.IdReflector">Eliminar</button>*@
            </div>

        </div>
    </div>
</div>

}

1 respuesta 1

1

Una vez que mandas llamar el Index, no es posible detenerlo. Puedes hacerlo por un ajax, regresar un resultado y mandar el mensaje, luego mandar pintar tu mensaje emergente y al final redireccionar.

O usando MVC puedes guardar tu mensaje en un TempData

TempData["Mensaje"] = "Registro guardado correctamente.";

Y mostrar ese tempdata en tu index (Ejemplo usando boostrap)

@{
    string classAlerta = string.Empty;
}

@if (TempData["Mensaje"] != null)
{

    if (esError)
    {
        classAlerta = "alert alert-danger";
    }
    else
    {
        classAlerta = "alert alert-success";
    }

    <div class="row" style="margin-top:2%;">
        <div class="col-md-8">
            <div class="@classAlerta" role="alert">
                <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                @TempData["Mensaje"].ToString()
            </div>
        </div>
    </div>
}

Tu Respuesta

Al pulsar en “Publica tu respuesta”, muestras tu consentimiento a nuestros términos de servicio, política de privacidad y política de cookies

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