I am having an issue trying to bind 2 database values to the URL my global.asax file is correct as
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}/{stitle}", // URL with parameters
new { controller = "article", action = "Index", id = UrlParameter.Optional, stitle= UrlParameter.Optional} // Parameter defaults
);
The issue i am having is with my controller for some reason i cannot get the Second value to return here is my controller code
public ActionResult Detail(int id,string stitle)
{
Article article = db.Articles.Find(id);
stitle = (from s in db.Articles where id == s.ArticleID select s.stitle).FirstOrDefault();
return View(article);
}
is there someway that i can return stitle or include it within the article since the stitle is a string value from the database.
Only the last parameter of a route can be optional. So in your case the
idparameter can no longer be optional:Then make sure that you are generating the proper link to this action:
and the generated url should look like this: