开发者

Having a problem outputting the correct url from an ActionLink

开发者 https://www.devze.com 2023-04-05 11:12 出处:网络
I am trying to output the following URL using the ASP.Net MVC3 framework and I am a total noob at this stuff:

I am trying to output the following URL using the ASP.Net MVC3 framework and I am a total noob at this stuff:

http://www.foo.com/controller/action/开发者_开发百科1

Here is my code so far:

@Html.ActionLink("Click here!", "action", new { Controller = "controller" })

This gives me:

http://www.foo.com/controller/action/

What do I need to get a simple hardcoded 1 in there at the end?


To specify route parameters you'll need to use the following signature

@Html.ActionLink("Click here!", "action", "controller", new {id = 1}, null })

The null at the end represents the HtmlAttributes which you can specify if you like

Also checkout this question "HTML.ActionLink method" for a great description of how ActionLink should be used


You need to add another routing parameter:

@Html.ActionLink("Click here!", "action", new { Controller = "controller", id = 1 })

I'm assuming that you're trying to use a route of the form "{controller}/{action}/{id}"

0

精彩评论

暂无评论...
验证码 换一张
取 消