I am trying to build simnple search utility searching my Employees by last Name.
Here is my Razor View
@using(Html.BeginForm("Index","Employee", FormMethod.Post))
{
<p>
Search employees by Last Name : @Html.TextBox("SearchString")
<input type="submit" value="Submit" name="Search" />
</p>
}
Here is my Controller
// GET: /Employee/
public ActionResult Index(string lastName)
{
var employees = db.Employees;
if (!String.IsNullOrEmpty(lastName))
{
employees = employees.Where(p => p.LastName.ToUpper().Contains(lastName.ToUpper()));
}
return View(employees.ToList());
}
Debugging shows the Submit button posting back to the index method, but the value lastName returned to the Index method is always null. How can I pass the lastName correctly?