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?

1

1 Answer 1

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                
        }
    );
Sign up to request clarification or add additional context in comments.

4 Comments

thanks, but my controller just get newsId. Should I take newsTitle in controller too?
so you want to use news title instead of news id in the controller, or you must use newsid to identify the news?
No I use news id to identify the news to show, but want to replace news title in url.
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.