I can not get the view parameter in the controller

0

Remembering that while running it does not return any error

Controller

using CRUD.Aplicação;
using DocumentoObjeto.dominio;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;


namespace Tcc1._6._0.Controllers
{
    public class LocalizarController : Controller
    {


        // GET: Localizar

        public ActionResult Index()
        {
            return View();
        }


        public ActionResult RetornoObjetoPorCpf()
        {


            return View();
        }



        [HttpPost]
        public ActionResult RetornoObjetoPorCpf(string cpf)
        {

            ViewBag.cpf = cpf;

            var appAluno = new Inserir_usuario();
            var aluno = appAluno.ListarPorCpf(cpf);

            if (aluno == null)
                return HttpNotFound();

            return View(aluno);
        }




    }
}

View

@model DocumentoObjeto.dominio.Objeto

<div>
    <h4>Objeto</h4>
    <hr />
    <dl class="dl-horizontal" >
        <div class="form-horizontal">


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



            <div class="form-group">
                <div class="col-md-offset-2 col-md-10">
                    <input type="submit" value="Buscar" class="btn btn-default" />
                </div>
            </div>
        </div>

        <dt>
            @Html.DisplayNameFor(model => model.nome)
        </dt>

        <dd>
            @Html.DisplayFor(model => model.nome)
        </dd>

        <dt>
            @Html.DisplayNameFor(model => model.cpf)
        </dt>

        <dd>
            @Html.DisplayFor(model => model.cpf)
        </dd>



    </dl>
</div>
<p>
    @Html.ActionLink("Edit", "Edit", new { /* id = Model.PrimaryKey */ }) |
    @Html.ActionLink("Back to List", "Index")
</p>
    
asked by anonymous 21.10.2018 / 21:47

1 answer

1

The submit will send all information that is within form , and notice that in your code the submit is outside the form that contains the fields. I suggest putting your fields as in the following example:

 @using (Html.BeginForm("RetornoObjetoPorCpf", "LocalizarController", FormMethod.Post))
{
            @Html.LabelFor(model => model.cpf, htmlAttributes: new {@class = "control-label col-md-2"})
            <div class="col-md-10">
                @Html.EditorFor(model => model.cpf, new {htmlAttributes = new {@class = "form-control"}})
                @Html.ValidationMessageFor(model => model.cpf, "", new {@class = "text-danger"})
            </div>

            <div class="col-md-offset-2 col-md-10">
                <input type="submit" value="Buscar" class="btn btn-default"/>
            </div>
}
    
21.10.2018 / 22:03