There are two problems one might have with this:
@Html.ActionLink(@item.Name, "Details?Id=" + @item.Id)
They are:
- This error appears:
A potentially dangerous Request.Path value was detected from the client (?).
...for which the cure is to put the following in the system.web section of the Web.config:<httpRuntime requestValidationMode="2.0" requestPathInvalidCharacters="" />
<pages validateRequest="false" />
- The HTML comes out as:
<a href="/Whatever/Details%3fId%3d3ab1172a-6d38-406a-a1f4-36726743226e">Foo</a>
...and you don't care for the encoding. The fix:@MvcHtmlString.Create(@Html.ActionLink(@item.Name, "Details?Id=" + @item.Id).ToString().Replace("%3f", "?").Replace("%3d", "="))
Yay!
While I was struggling to figure this out, I learned the following:
- The third parameter here is the Controller:
@Html.ActionLink("Help Page", "Help", "Home")
- This is an example of creating a variable outside of a foreach loop
@{
var foo = "bar";
}
@foreach(var baz in qux)
{
@foo<br />
} - These are some good links:
I use this syntax in Razor
ReplyDelete@Html.ActionLink("Click Here", "RedirectLink", new { id=Model.ID })
and it works :D
CMIIW
Thanks! This post is as old as can be from when I was first struggling with Razor.
Delete