Reputation: 1
Url rewrite code to use to for asp.net MVC4; I use to App_Start/RouteConfig.cs in the code down.
routes.MapRoute(
name: "subjectSefLink",
url: "{controller}/{seo}/{page}",
defaults: new
{
controller = "subject",
action = "Index",
seo = UrlParameter.Optional,
page = UrlParameter.Optional
});
I use the Controller;
public class SubjectController : Controller
{
public ActionResult Index(string seo, int page)
{
return View();
}
}
but does not work; The output of the code = 404 not found
Upvotes: 0
Views: 884
Reputation: 11570
You have to declare int page
variable as nullable
. As in routing, you have declared page
variable as Optional
. So, the action method in controller should be like this
public class SubjectController : Controller
{
public ActionResult Index(string seo, int? page)
{
return View();
}
}
Upvotes: 1