I can not figure out why ActionLink is not generating the url correctly in this one instance.
I have a controller called Activity and a view called Show. From there I'm trying to create a link to the ServiceCall controller, Show view. From within any view on the ServiceCall this works fine:
<%= Html.ActionLink(Html.Encode(sc.CallNumber), "Show", new { callNumber = "100" })%>
From the Activity view, this is not working:
<%= Html.ActionLink(Html.Encode(sc.CallNumber), "Show", "ServiceCall", new { callNumber = "100" })%>
It is generating a link like http://localhost/Activity/Show/12?Length=11
After some research I 开发者_JAVA百科decided to try this:
<%= Html.ActionLink(Html.Encode(sc.CallNumber), "Show", new { controller = "ServiceCall" }, new { callNumber = "100" })%>
That gives me a url of http://localhost/ServiceCall/Show but does not give the callNumber. Any ideas?
This is in my routes:
routes.MapRoute(
"ShowCall",
"ServiceCall/Show/{callNumber}",
new {controller = "ServiceCall", action = "Show", callNumber = ""}
);
I think you are not calling the correct override. You need:
<%= Html.ActionLink(
sc.CallNumber,
"Show",
"ServiceCall",
new { callNumber = "100" },
null) %>
Notice the extra null
. I had recently similar problem.
Edit: Also, I'm sure you don't need the Html.Encode
. It's already being encoded.
Try this:
<%= Html.ActionLink(Html.Encode(sc.CallNumber), "Show", "ServiceCall", new { callNumber = "100" }, null)%>
精彩评论