-2
I’m trying to make a search button on mine view of films, but gives me a mistake to say that I can’t have a zero value. Why? And what do I have to do?
Controller:
public ActionResult Index(string searchBy, string search)
{
MovieViewModel[] movies = db.MoviesData.Select(movie => new MovieViewModel
{
MovieID = movie.MovieID,
MovieName = movie.MovieName,
MovieDescription = movie.MovieDescription,
MovieCategory = movie.MovieCategory,
MovieYear = movie.MovieYear
}).ToArray();
if (searchBy == "Categoria")
{
return View(movies.Where(x => x.MovieCategory==search || search == null).ToList());
}
else
{
return View(movies.Where(x => x.MovieName.StartsWith(search) || search == null).ToList());
}
}
View part of the search button:
<p>
@using (Html.BeginForm("Index", "Movies", FormMethod.Get))
{
<b>Search By: </b>@Html.RadioButton("searchBy", "Nome", true) <text> Nome </text>
@Html.RadioButton("searchBy", "Categoria") <text> Categoria </text> <br />
@Html.TextBox("search") <input type="submit" value="Search" class="btn btn-default" />
}
</p>
The mistake you make is this::
'System.Argumentnullexception: The value cannot be null. Parameter name: value'
What is the exact line on which the error occurs?
– Ronaldo Araújo Alves
@Ronaldoaraújoalves gives error in this: Return View(Movies. Where(x => x.MovieName.Startswith(search) || search == null). Tolist());
– Diogo Teixeira
Want to ride a Minimum, Complete and Verifiable Example with the real situation, otherwise a solution beyond what has been presented.
– Bacco