Confirmation Mode

3

I need to create a modal with a warning to the user when he clicks the save button. I already have a similar one that is used for when the user clicks 'Delete' which is in my view / Delete

<h4 class="modal-title">Atenção!</h4>
<div class="modal-body">
Tem certeza que deseja excluir <strong>@Html.DisplayFor(model => model.Nome) </strong>?
</div>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()    
<div class="modal-footer">
    <input class="btn btn-primary btn-danger" type="submit" value="Excluir" />
    <a class="btn btn-default" onclick="FechaModal();">Cancelar</a>
</div>
}

Controller

    [HttpPost, ActionName("Delete")]
    [ValidateAntiForgeryToken]
    public ActionResult DeleteConfirmed(int id)
    {
        Curso curso = db.Cursos.Find(id);
        db.Cursos.Remove(curso);
        db.SaveChanges();
        return RedirectToAction("Index");
    }

I created a similar model called 'Aware' which is what I want to open when the user clicks save

<div class="modal-body">
Apresente pessoalmente o comprovante de: @Html.DisplayFor(model => model.Nome)
</div>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()    
<div class="modal-footer">
     <input class="btn btn-primary" type="submit" value="Salvar" />
    <a class="btn btn-default" onclick="FechaModal();">Cancelar</a>
</div>

CourseController

    [HttpPost, ActionName("Ciente")]
    [ValidateAntiForgeryToken]
    public ActionResult Createconfirmed(Curso curso)
    {
        if (ModelState.IsValid)
        {
            curso.AtualizaDiploma();
            db.Cursos.Add(curso);
            db.SaveChanges();
            return RedirectToAction("Index", "Perfis");
        }
    }

My View Editor Templates Course is below. When you click on Save from this view, the modal 'Acknowledgment' should appear for confirmation

@model Competências.Models.Curso

@using (Html.BeginForm(null, null, FormMethod.Post, new { enctype = "multipart/form-  data" }))

@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
@Html.HiddenFor(model => model.PerfilId) 

<div class="modal-body">
        <div class="col-md-12">
            @Html.LabelFor(model => model.Nome)
            @Html.TextBoxFor(model => model.Nome, new { @class = "form-control" })
            @Html.ValidationMessageFor(model => model.Nome)
        </div>
    </div>

    <input class="btn btn-primary" type="submit" value="Salvar" />
    <a class="btn btn-default" onclick="FechaModal();">Cancelar</a>

My Course / Create view

@model Competências.Models.Curso
<div class="modal-header">
<h4 class="modal-title">Novo Curso/Formação</h4>
</div>
@Html.EditorForModel()

and my EditorTemplate / Course

I have already created a controller named Aware but then the modal appears with the information but not saved. Can someone tell me where the error is and make this confirmation in the correct way?

    
asked by anonymous 11.07.2014 / 16:21

1 answer

3

It is missing within its form the Id of the record to be deleted. Modify your View to the following:

<div class="modal-body">
    Apresente pessoalmente o comprovante de: @Html.DisplayFor(model => model.Nome)
</div>
@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()    
    @Html.Hidden("id", Model.CursoId)

    <div class="modal-footer">
        <input class="btn btn-primary" type="submit" value="Salvar" />
        <a class="btn btn-default" onclick="FechaModal();">Cancelar</a>
    </div>
}

As the modal view code, the change is very similar.

EDIT

For the creation case, you need to put the fields as a form in some way. My suggestion is as follows:

<div class="modal-body">
    Apresente pessoalmente o comprovante de: @Html.DisplayFor(model => model.Nome)
</div>
@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()    
    @Html.HiddenFor(model => model.CursoId)
    @Html.HiddenFor(model => model.Nome)
    @Html.HiddenFor(model => model.DataInicio)
    @* Coloque os outros campos aqui *@

    <div>Nome: @Model.Nome</div>
    <div>Data de Início: @Model.DataInicio</div>
    <!-- Mostre os demais campos aqui -->

    <div class="modal-footer">
        <input class="btn btn-primary" type="submit" value="Salvar" />
        <a class="btn btn-default" onclick="FechaModal();">Cancelar</a>
    </div>
}
    
11.07.2014 / 19:09