Use submit to submit a form, within modal, using bootstrap

1

I'm trying to submit a form within a modal, but it's not submitting what I'm sending in the tag.

My VIEW:

<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">Novo</button>

    <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="exampleModalLabel">Nova Área Responsável</h4>
                </div>
                <div class="modal-body">
                    @using (Html.BeginForm("Index", "AreaResponsavel", FormMethod.Post, new { enctype = "multipart/form-data", id = "form" }))
                    {
                        @Html.AntiForgeryToken()
                        @Html.ValidationSummary(true)

                        <fieldset>
                            <div class="form-group">
                                <label for="recipient-name" class="control-label">Descrição</label>
                                <input type="text" class="form-control" id="descricao">
                            </div>
                        </fieldset>
                        <div class="modal-footer">
                            <button type="submit" class="btn btn-primary">Salvar</button>
                            <button type="button" class="btn btn-default" data-dismiss="modal">Fechar</button>
                        </div>

                    }

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

My Controller:

public ActionResult Index()
    {
        var listaDeAreaResponsavel = appAreaResponsavel.ListarTodos();
        return View(listaDeAreaResponsavel);
    }

    [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult Index(AreaResponsavelDominio areaResponsavel)
    {
        if (ModelState.IsValid)
        {
            appAreaResponsavel.Salvar(areaResponsavel);
            return RedirectToAction("Index");
        }
        return View(areaResponsavel);
    }

My Model:

public class AreaResponsavelDominio
{
    [DisplayName("Código")]
    public int CodAreaResponsavel { get; set; }

    [DisplayName("Descrição")]
    public string Descricao { get; set; }
}

I debugged, and the values being:

    
asked by anonymous 11.05.2015 / 16:28

2 answers

2

You need to add the name to the input

<input type="text" class="form-control" id="descricao" name="Descricao">

Binding is done from the name attribute of the tag.

    
04.05.2016 / 14:59
0

Here is an example I use on a system and it works fine.

<div id="modal-control" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" class="modal fade">
    <div class="modal-dialog modal-sm">
        <div class="modal-content">
            <form id="form" method="post" action="">
                <button type="submit" class="btn btn-success">Salvar</button>
            </form>
        </div>
    </div>
</div>
    
04.05.2016 / 14:49