Why is my ActionLink not working correctly?
I can't 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 am trying to create a link to the ServiceCall controller, Show View. From any view on the ServiceCall, this works great:
<%= Html.ActionLink(Html.Encode(sc.CallNumber), "Show", new { callNumber = "100" })%>
In Activity view, this doesn't work:
<%= Html.ActionLink(Html.Encode(sc.CallNumber), "Show", "ServiceCall", new { callNumber = "100" })%>
It generates a link like http: // localhost / Activity / Show / 12? Length = 11
After some research, I decided to try the following:
<%= Html.ActionLink(Html.Encode(sc.CallNumber), "Show", new { controller = "ServiceCall" }, new { callNumber = "100" })%>
This gives me the URL http: // localhost / ServiceCall / Show , but it doesn't give me the call number. Any ideas?
This is on my routes:
routes.MapRoute(
"ShowCall",
"ServiceCall/Show/{callNumber}",
new {controller = "ServiceCall", action = "Show", callNumber = ""}
);
source to share
I think you are not calling the correct override. You need:
<%= Html.ActionLink(
sc.CallNumber,
"Show",
"ServiceCall",
new { callNumber = "100" },
null) %>
Pay attention to the additional null
. I recently had a similar problem.
Edit: Also, I'm sure you don't need one Html.Encode
. It's already coded.
source to share