0

net mvc 3 并尝试创建博客应用程序。我想要一个包含 urlheader 的 url,例如:

博客/详情/第三篇文章

但是,我得到一个网址,它是这样的:

Blog/Details/3?urlHeader=Third-post

我究竟做错了什么?

我的博客控制器如下:

public ViewResult Details(int id, string urlHeader)
{
    var blogs = blogrepository.GetBlog(id);
    var recentblogs = blogrepository.FindRecentBlogs(5);
    var archivelist = blogrepository.ArchiveList();
    BlogDetailsViewModels viewModel = new BlogDetailsViewModels { Blog = blogs, RecentBlogs = recentblogs, ArchiveList = archivelist };
    return View(viewModel);
}

路由方法如下:

 routes.MapRoute(
        "BlogDetail", // Route name
        "Blog/Details/{urlHeader}", // URL with parameters
        new { controller = "Blog", action = "Details" }, // Parameter defaults
        new { urlHeader = "" } // Parameter constraints
    );

链接如下:

@Html.ActionLink(Model.Title , "Details", "Blog", new { id = Model.BlogID, urlHeader = Model.UrlHeader }, null)
4

1 回答 1

0

您可能有以下路线:

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    routes.MapRoute(
        "Blog",
        "Blog/Details/{id}/{urlHeader}",
        new { controller = "Blog", action = "Details", urlHeader = UrlParameter.Optional },
        new { id = @"\d+" }
    );

    routes.MapRoute(
        "Default",
        "{controller}/{action}/{id}",
        new { controller = "Home", action = "Index", id = UrlParameter.Optional }
    );
}
于 2012-07-28T09:37:32.157 回答