html.actionlink не создает правильные ссылки - PullRequest
0 голосов
/ 07 января 2012

Мои маршруты настроены так в моем 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
        );

Вот мои два контроллера

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();
    }
}

Где-то на домашней странице, у меня есть ссылка html, например

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

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

Я ожидаю два URL, как

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

Но это не создание этих URL.

Я делаю что-то не так.

Помощь будет оценена.

// Обновление моего вопроса здесь

На самом деле это работает

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

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

Передача нулевого значения в качестве последнего параметра.

Не знаю почему, но это работает.

Приветствия

Parminder

1 Ответ

1 голос
/ 07 января 2012

1001 * попробовать *

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