I am trying to search a movie from a list. However, the search string always returns null.
My Controller Code
public ActionResult Index()
{
return View(db.Movies.ToList());
}
public ActionResult Search(string searchstring)
{
var movies = from m in db.Movies
where m.Title.Contains(searchstring)
select m;
return View(movies.ToList());
}
// GET: Movies/Details/5
public ActionResult Details(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Movie movie = db.Movies.Find(id);
if (movie == null)
{
return HttpNotFound();
}
return View(movie);
}
Routing Configuration
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Movies", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "Search",
url: "{controller}/{action}/{searchstring}"
);
I am able to get the list of movies from Index action. The URL I am passing is http://localhost:52872/Movies/Search/GodFather
However if I place my Search route above the Default route, it works fine, but the edit, and details does not work.