Reputation: 1563
How to generate some URL like http://mysite/some-id using below method?
Note: I do not want to use controller name and action name in url. because the main site used this structure and my boss does not want to change it.
public class StoryController : Controller
{
public ActionResult Index(string id)
{
if(id =="some-id"){
}
return View();
}
}
Upvotes: 0
Views: 69
Reputation: 25370
I don't know what version of MVC you are using, but if you are on the newest version or .NET Core, if you used routing attributes, you'd achieve this by:
[Route("")]
public class StoryController : Controller
{
[Route("{id}")]
public ActionResult Index(string id)
{
if(id =="some-id"){
}
return View();
}
}
Having a single parameter that is a string on your index-like route will definitely pose problems later with the routing engine though, when you try to add more controllers and views
Upvotes: 2