添加冗余信息发送到MVC路线 [英] Adding Redundant Information to a MVC Route
问题描述
当你来到这个问题,你会发现这个问题的标题是在地址栏和您点击链接到这里。我不知道确切的术语,以便发现很难寻找,但我该怎么做同样的事情?也就是说,我如何将数据添加到这纯粹是为了显示/搜索引擎的地址栏。
As you come to this question you'll notice the title of the question is in the address bar and the link you clicked on to get here. I am not sure the exact terminology so found it difficult to search for but how can I do something similar? That is, How can I add data to the address bar which is purely for show/search engines.
感谢
推荐答案
拍摄堆栈溢出问题的例子像这样的网址是:
Taking the example of a Stack Overflow question like this one the URL is:
<一个href=\"http://stackoverflow.com/questions/1142480/adding-redundant-information-to-a-mvc-route\">so.com/questions/1142480/adding-redundant-information-to-a-mvc-route
不过,URL的功能部分是:
However, the functional part of the URL is:
这是实现的方式是通过定义这样的路线:
The way this is achieved is by defining a route like this:
routes.MapRoute(
"questions",
"questions/{id}/{title}",
new { controller = "Questions", action = "Details", title = "" });
然后创建一个链接到它是这样的:
You then create a link to it like this:
<%= Html.RouteLink("Adding Redundant Information to a MVC Route",
new
{
controller = "Questions",
id = 1142480,
title = "adding-redundant-information-to-a-mvc-route"
}
)
%>
我会想象的URL标题从实际的称号下外壳创建的,以替换破折号空间和几个其他的事情(逃逸/条带化坏字符)。
I would imagine the URL title is created from the actual title by lower casing, replacing spaces with dashes and a couple of other things (escaping/striping bad characters).
只要你的SEO路线其他任何匹配的路由搜索引擎优化航线将使用之前出现。
So long as your SEO route appears before any other matching route the SEO route will be used.
有关完整清晰的控制实际上是这样的:
For complete clarity the controller would actually be like this:
public class QuestionsController : Controller
{
public ActionResult Details(int id)
{
// stuff for display - notice title is not used
}
}
这篇关于添加冗余信息发送到MVC路线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!