Retrieve view value for controller

4

Goal: Retrieve view value for controller [HttpPost]

I created a generic class with gets and sets

public int ListarDadosCarteira_Resultado { get; set; }
public string ListarDadosCarteira_Descricao { get; set; }    
public int ListarDadosCarteira_Total { get; set; }

Updating !! Loading View Full usage two model is only one because I took the second one for testing.

    @model Tuple<Generic>
    @{
    ViewBag.Title = "Index";}
    <div class="painel">
    <div class="painel-header">
        <div class="painel-header-text-search">Carteira Mapa</div>
    </div>

    <div class="painel-content">
        @using (Html.BeginForm())
        {  
            <fieldset>
            <legend>Index</legend>


                @Html.TextBoxFor(model => model.Item1.ListarDadosCarteira_Total , new { @class = "newText" })            
                @Html.TextBoxFor(model => model.Item1.ListarDadosCarteira_Descricao , new { @class = "newText" })  
                @Html.TextBoxFor(model => model.Item1.ListarDadosCarteira_Resultado , new { @class = "newText" })  

                <div class="field-row">
                    <div class="editor-label">
                        <div class="posicao-botao">
                                <input type="submit" value="Pesquisar" class="button-search" title="Pesquisar Funcionario Fixa" />
                        </div>
                    </div>
                </div>    
            </fieldset>            
        }
    </div>
</div>
     @section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}

Now comes my question as I retrieve the value entered when I perform a [HttpPost]?

I usually bring it like this.

[HttpPost]
    public ActionResult Index(Generic generica)
    {
    }

But your self does not bring me values.

    
asked by anonymous 27.04.2016 / 21:47

1 answer

5

The idea is the same that you posted, create your model to receive in your Action:

public class Generic
{
    public int ListarDadosCarteira_Resultado { get; set; }
    public string ListarDadosCarteira_Descricao { get; set; }
    public int ListarDadosCarteira_Total { get; set; }
}

Then create your controller with your action:

public class HomeController : Controller
{
    [HttpPost]
    public ActionResult MetodoParaReceberSeuPost(Generic generica)
    {
        return null;
    }
}

And then your view, remembering to type using @model

@model Mvc4WebBootstrap1.Models.Generic

@using (Html.BeginForm("suaAction", "seuController"))
{ 
    @Html.TextBoxFor(model => model.ListarDadosCarteira_Descricao)
    @Html.TextBoxFor(model => model.ListarDadosCarteira_Resultado)
    @Html.TextBoxFor(model => model.ListarDadosCarteira_Total)

    <input type="submit" value="enviar" />
}

No more is this:)

    
27.04.2016 / 22:00