I'm learning ASP.NET MVC C # programs and would like to know how I pass data from a textbox to a controller. That is, I want to enter a value (id) in the View Index in a textbox and when I click Submit it returns me to View Details with the id that I typed in the Index view. This example is it pick up by the Name, Tel and CPF through the id that I type in the view index. The view details is working perfectly, when I pass the id by url it shows me the data of the person.
Controller
public class HomeController : Controller
{
//
// GET: /Home/
public ActionResult Index()
{
return View();
}
public ViewResult Details(int id )
{
ClienteEntity cliente = new ClienteEntity(id);
// var cli = cliente.FetchUsingPK(id);
return View(cliente);
}
}
{
ClienteEntity cliente = new ClienteEntity(id);
// var cli = cliente.FetchUsingPK(id);
return View(cliente);
}
}
View of the Index
@{
ViewBag.Title = "Index";
}
<h2>Digite um Numero: @Html.TextBox("id")</h2>
<input type="submit" value="Enviar" />
View the Details
<h2>Dados Do Cliente</h2>
<h2>Nome: @Model.NomeCliente</h2>
<h2>CPF: @Model.Cpf</h2>
<h2>Tel: @Model.Tel</h2>