0

I have my routes configured like this in my global.asax

  routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
           "poems-by-profile", // Route name
           "profile/{id}/{name}/poems", // URL with parameters
           new { controller = "poems", action = "Index", id = "", name = "" } // Parameter defaults
        );

        routes.MapRoute(
           "profile", // Route name
           "profile/{id}/{name}", // URL with parameters
           new { controller = "profile", action = "Index", id = "", name = "" } // Parameter defaults
       );


        routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}/{name}", // URL with parameters
            new { controller = "Home", action = "Index", id = UrlParameter.Optional, name = UrlParameter.Optional } // Parameter defaults
        );

Here are my two controllers

public class ProfileController : BaseController
{
    public  ActionResult Index(int id, string name)
    {
        return View();
    }
}

public class PoemsController : BaseController
{

    public ActionResult Index(int id, string name)
    {
        return View();
    }
}

Somewhere on home page, I have html action link like this

@Html.ActionLink("Profile", "index", "Profile", new { id = 1, name = "someuser" })

@Html.ActionLink("Poems by ", "index", "poems", new { id = 1, name = "someuser" })

I am expecting two urls like

http://localhost/profile/1/someuser
http://localhost/profile/1/someuser/poems

But it is not creating these urls.

Am I doing something wrong.

Help will be appreciated.

//Updating my question here

Actually this one works

@Html.ActionLink("Profile", "index", "Profile", new { id = 1, name = "someuser" },null)

@Html.ActionLink("Poems by ", "index", "poems", new { id = 1, name = "some user" },null)

Passing null as last parameter.

Dont know why, but it works.

Cheers

Parminder

2
  • 1
    what are the links you actually generate? Commented Jan 7, 2012 at 7:34
  • @Floradu88 it was generating home page link (localhost) Commented Jan 7, 2012 at 7:48

1 Answer 1

1

try

@Html.ActionLink("Profile", "index", new {controller="Profile" id = 1, name = "someuser" })
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, 3nigma. It works. I have updated my question. So one more option also works.
3nigma can't u focus on ur exams at least for some time :P

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.