I have a web form that ask a user for their Id. My overall goal is to be able to take the id and call a function and return a class. The class would return the user name, email, and city.
I am not that far yet. Im still on the first phase.
Is my html code correct? when the button is hit, I want the user input to get pass to the controller?
I want to get the text from the input text in the html. I want to receive the text from the input in my html form. then take that text to the controller which call a user class and display that class
<html>
<div align="center">
<form id="searchUser" method="post" action="">
<table align="center">
<tr>
<td class="label">
Enter ID:
</td>
<td>
<input type="text" name="UserId" id="UserId" />
</td>
</tr>
<tr>
<td>
<button class="searchButton" id="searchButtong">Search</button>
</td>
</tr>
</table>
</form>
</div>
<hr />
</html>
Search Controller
public class SearchController : Controller
{
//
// GET: /Search/
public ActionResult Index()
{
return View();
}
public string searchUser(string UserId)
{
UserId = Request["UserId"];
return UserId;
}
}
The easiest way would probably be to make an AJAX request to the action, and have the action return the proper data in JSON.