如何根据以下模式映射路线?
你如何映射这个网址
/Topic/topicName/action?topicId=someInt
其中 Topic 是控制器名称(这是 const - 它始终读取“Topic”),
topicName 被忽略
action 是操作名称,
someInt 是“action”的 topicId 参数。
以下是几个示例:
/Topic/c-sharp/AddQuestion?topicId=1
调用:
控制器:主题
操作:添加问题
topicId =1
这是 TopicConroller
中操作的特征
public ActionResult AddQuestion(int topicId)
另一个示例:
/Topic/MySql-queries/AddSubTopic?topicId=1
调用:
控制器:主题
操作:添加子主题
topicId =1
这是 TopicConroller
public ActionResult AddSubTopic(int topicId)
等中操作的签名(主题控制器中的所有操作仅接收一个参数 - 即主题的 id)。
How do you map this url
/Topic/topicName/action?topicId=someInt
Where Topic is the controller name (this is const - it always reads "Topic"),
topicName is being ignored
action is action name,
and someInt is the topicId argument for "action".
Here are couple of examples:
/Topic/c-sharp/AddQuestion?topicId=1
To invoke:
Controller: Topic
Action: AddQuestion
topicId =1
Where this is the action's singnature in TopicConroller
public ActionResult AddQuestion(int topicId)
Another example:
/Topic/MySql-queries/AddSubTopic?topicId=1
To invoke:
Controller: Topic
Action: AddSubTopic
topicId =1
Where this is the action's singnature in TopicConroller
public ActionResult AddSubTopic(int topicId)
etc. (all actions in Topic controller receive only one argument - that is the topic's id).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您
关心主题名称,您可以让控制器操作将其作为操作参数:
where you would have:
and if you cared about the topic name you could have your controller action take it as action parameter:
我发现这个工具路由调试器对于测试我的完美路由非常有用
http://haacked.com/archive/2008/03/13/url-routing-debugger.aspx
现在它还有一个 nuget 包。
也可能对进一步的场景有所帮助......
I found this tool route debuger very useful to test my way around to the perfect route
http://haacked.com/archive/2008/03/13/url-routing-debugger.aspx
it has also a nuget package now.
Might help for further scenarios, too...
你尝试过吗:
另一种方法是像stackoverflow那样做。看一下问题 url,问题在 id 之后,可能会被忽略。
Have you tried:
Another way is to do it like stackoverflow. Take a look at question url, question is after id and is probably ignored.