Get input value of a textbox in asp.net mvc

1

How do I get the new input value from a textbox when I click the button? I need to make it like a update that would go to the bank.

    
asked by anonymous 14.08.2015 / 16:20

1 answer

2

The correct way to do this is through <form> . Using MVC and Razor, it is used as follows:

@model MeuProjeto.Models.MeuModel

@using (Html.BeginForm()) 
{
    @Html.TextBoxFor(model => model.MeuCampo)

    <button type="submit">Enviar</button>
}

Obviously, this only makes sense if you have a Model defined like this:

namespace MeuProjeto.Models
{
    public class MeuModel
    {
        public String MeuCampo { get; set; }
    }
}

The Controller will receive the form data as follows:

[HttpPost]
public ActionResult MinhaAction(MeuModel model) 
{
    // O valor do campo em tela vai estar preenchido em 
    // model.MeuCampo
}
    
14.08.2015 / 17:08