Take the value of an input type=text and play in a variable

Asked

Viewed 3,428 times

1

I am using ASP.Net-mvc4] in my C# project in Visual Studio and I need to get the value of input type=text that’s in my view, and play in a variable on my controller, but I couldn’t find a way to do it.

I would give the example I am doing, but when I put the html here he recognizes as command.

2 answers

1


Two ways:

1. Passing the entire model to the Controller

[HttpPost]
public ActionResult AcaoDoController(MeuModel meuModel) { ... }

2. Passing the Field name as Parameter

[HttpPost]
public ActionResult AcaoDoController(String fieldDoForm) { ... }

In CSHTML:

<input type="text" name="fieldDoForm" />

0

The @gypsy-Morrison-Mendez response is correct, but you can also use a Helper: @Html.Textbox("fieldDoForm")

  • This would be a complement. This Razor code generates the equivalent tag. The goal is to understand the passing of parameters to the Form, which can be done with pure HTML.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.