So i am building a book search page and everything else works (search by title, author etc) but I cant figure out how to search by the unique number which is an int in our db -- I've tried several things like converting to int32, turning IDnumber into a string etc but still cant find a solution
parameters:
public ActionResult Index(int IDnumber, string LnameString, string FnameString, string bookGenre,string searchString)
{
//LINQ query to select books
var books = from m in db.Book
select m;
//ID Number
if (IDnumber != null)
/* the if statement gives the following warning which i cannot resolve: the result of the expression is always 'true' since a value of type 'int' is never equal to null of type int?*/
{
books = books.Where(x => x.BookID == IDnumber);
}
...
}
View code:
<p>
@Html.ActionLink("Create New", "Create")
@using (Html.BeginForm("Index", "Books")){
<p>
Genre: @Html.DropDownList("bookGenre", "All")
Title: @Html.TextBox("SearchString") <br />
Author First Name: @Html.TextBox("FnameString")
Author Last Name: @Html.TextBox("LnameString") <br />
ID Number: @Html.TextBox("IDNumber")
<input type="submit" value="Filter" />
</p>
}
Exact error:
The parameters dictionary contains a null entry for parameter 'IDnumber' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult Index(Int32, System.String, System.String, System.String, System.String)' in 'SafariBooksGroup15.Controllers.BooksController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter. Parameter name: parameters
IDnumber is already of type int
no need to do any converting on that.. take the time to read / debug your code – MethodManint?
forIDnumber
and include it in search if it has value. – Reza Aghaei