【发布时间】:2013-04-23 14:12:33
【问题描述】:
嗨,我将像这样在我的博客网址中应用 Id 和 slug 的混合物作为网址
http://stackoverflow.com/questions/16286556/using-httpclient-to-log-in-to-hpps-server
为此,我在 global.asax 中定义了这个 Url
routes.MapRoute("IdSlugRoute", "{controller}/{action}/{id}/{slug}",
new {controller = "Blog", action = "Post", id = UrlParameter.Optional,slug=""});
但是当我运行我的应用程序时,Url 看起来像这样:
http://localhost:1245/Blog/Post?postId=dd1140ce-ae5e-4003-8090-8d9fbe253e85&slug=finally-i-could-do-solve-it
我不想拥有那些?和 = 在网址中!我只想用斜线将它们分开 请问我该怎么办??
但是返回这个 Url 的 actionresult 的方式是这样的:
public ActionResult Post(Guid postId,string slug)
{
var post = _blogRepository.GetPostById(postId);
return View("Post",post);
}
【问题讨论】:
-
你怎么称呼这条路线?你能提供一个你的 ActionLink 等的例子吗?
-
我刚刚编辑并添加了调用路由的actionreslust
-
您是否像这样从 ActionLink 调用它...
@Html.ActionLink("foo", "Post", new { controller = "Blog", postId = 1, slug = "foo-bar" }) -
@foreach(模型中的变量项){@Html.ActionLink(item.Title, "Post", "Blog", new { postId = item.Id, slug = item.UrlSlug }, null)}请不要将“ASP.NET MVC”简称为“MVC”。一种是框架,另一种是与语言无关的设计模式。这就像调用 IE - “互联网”
标签: asp.net-mvc asp.net-mvc-routing