0

I have some new map routs but I want to change strings in url, for example in this mapping:

mysite/News/More/13

routes.MapRoute(
            name: "IssueNews",
            url: "News/More/{newsId}",
            defaults: new
            {
                controller = "News", 
                action = "More", 
                newsId = UrlParameter.Optional                
            }
        );

I want to use the title of news in my url and change it to this:

mysite/News/{news title here}

any suggestion?

tereško
  • 58,060
  • 25
  • 98
  • 150
Azarsa
  • 1,278
  • 3
  • 27
  • 37
  • relevant question : http://stackoverflow.com/questions/16248732/mvc-4-creating-slug-type-url/16252796 – shakib Mar 08 '14 at 16:05

1 Answers1

1

This Route should be able to work

    routes.MapRoute(
        name: "IssueNewsTitle",
        url: "News/newsId/{newsTitle}",
        defaults: new
        {
            controller = "News", 
            action = "More", 
            newsTitle= UrlParameter.Optional                
        }
    );
card_master
  • 418
  • 3
  • 12
  • thanks, but my controller just get newsId. Should I take newsTitle in controller too? – Azarsa Mar 08 '14 at 17:11
  • so you want to use news title instead of news id in the controller, or you must use newsid to identify the news? – card_master Mar 09 '14 at 00:45
  • No I use news id to identify the news to show, but want to replace news title in url. – Azarsa Mar 09 '14 at 07:00
  • If this is the case you may want to consider redirect the action after the action and append only newstitle or newsid and newstitle to another actionresult – card_master Mar 09 '14 at 08:46