3
I am learning programs in ASP.NET MVC C# and would like to know how I pass a 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 I typed in the Index view. This example is that it takes by the Name, Tel and CPF through the id I type in the view index. The Details view is working perfectly, when I pass the id by url it shows me the person’s data.
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);
}
}
Index View
@{
ViewBag.Title = "Index";
}
<h2>Digite um Numero: @Html.TextBox("id")</h2>
<input type="submit" value="Enviar" />
View from the Details
<h2>Dados Do Cliente</h2>
<h2>Nome: @Model.NomeCliente</h2>
<h2>CPF: @Model.Cpf</h2>
<h2>Tel: @Model.Tel</h2>
Thank you very much even working perfect here.
– Yehudi Mikhael
@Yehudimikhael, if your colleague’s answer has solved your question, you can close his post and don’t forget to give a vote on the answer if you haven’t already done.
– pnet
Can you tell me how I close and vote the answer ?
– Yehudi Mikhael
@Yehudimikhael The ideal is for you to take the Tour. Anyway, just below the punctuation, there’s a "V" icon that serves for you to accept the answer. To give votes, just click the arrow above the answer score. Anything just call me.
– Leonel Sanches da Silva