The parameters dictionary contains a null entry for parameter 'Id' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult SearchById(Int32)' in 'ModelBinding.Controllers.HomeController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter. Parameter name: parameters
@model IEnumerable< ModelBinding.Models.Employee> @{ Layout = null; } <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width" /> <title>Index</title> </head> <body> @using (Html.BeginForm("SearchById","Home")) { <p> <label>Enter ID:<input type="number" id="Id" /></label> </p> <button>Search</button> }
public ActionResult SearchById(int Id) { return View("Index", empList.Where(x => x.Id == Id)); }
name
<input>
id
<label>Enter ID: <input type="number" id="Id" name="Id" /></label>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)