2

From a View in a different Controller I am trying to re-route to the "ClnVwDet" Action in my Client Controller with this @Html.ActionLink.

@Html.ActionLink("Client View", "ClnVwDet", "Client")

ClientController.cs

public ActionResult ClnVwDet()
{
  int id = (int)TempData["id"];
  bool vw = true; int pn = 0;
  return RedirectToAction("Details", new { id, pn, vw });
}

No matter what actionName I use it always goes to the Client "Index" Action rather than the one I specify.

This corrected syntax for the ActionLink works.

@Html.ActionLink("Client View", "ClnVwDet", "Client", new { id = @Model.Id }, null)

Found answer here: Using Html.ActionLink to call action on different controller. See Banfords comment on cagdas's answer. To get the correct overload you need to add a fifth argument. If you want to pass routeValues with the (linkText, actionName, controllerName) overload you have to add the htmlAttribues to get the correct overload. (linkText, actionName, controllerName, routeValues, htmlAttribues)

Community
  • 1
  • 1
Joe
  • 4,143
  • 8
  • 37
  • 65
  • What URL actually gets rendered in the HTML? Typically, people find out that they find the URL they think is getting rendered isnt actually what is. – Tejs Apr 19 '12 at 17:28
  • 1
    Is the controller in an area? Or in the root Controllers folder? – danludwig Apr 19 '12 at 17:29
  • 4
    You are not matching the route you want to match, controller/view is not the problem. – Max Toro Apr 19 '12 at 17:33
  • 1
    What is the route that you have set up for it? – Shawn C. Apr 19 '12 at 17:39
  • Tejs. It ends up generating an error since the proper values are not being sent to the Client/Index Action. I know it is going to the Client/Index Action because when I run in debug it stops at the breakpoint in the Client/Index Action. – Joe Apr 19 '12 at 21:30
  • dan. All controllers are in the ProjectName/Controllers folder. – Joe Apr 19 '12 at 21:31
  • Shawn. Don't understand what you are asking. What you see is what I have. Could you elaborate? – Joe Apr 19 '12 at 21:33
  • Max. That is not very helpful. Could you elaborate on what I should be doing different? – Joe Apr 19 '12 at 21:34
  • This corrected syntax works. I've updated my question. @Html.ActionLink("Client View", "ClnVwDet", "Client", new { id = @Model.Id }, null) – Joe Apr 20 '12 at 00:41
  • Not sure why this fixed it. Found answer here: http://stackoverflow.com/questions/776781/problem-using-html-actionlink-to-call-action-on-different-controller Passing only 3 parameters passes the same three parameters as passing 5 does for it's first 3 parameters, but it worked with 5 and not 3. Anybody have any idea why that would be so? – Joe Apr 20 '12 at 17:44
  • The answer is contained here: stackoverflow.com/questions/776781/… Banfords comment on cagdas's answer. If you want to pass "routeValues" with the ("linkText", "actionName", "controllerName") overload you have to add the htmlAttribues to get the correct overload. ("linkText", "actionName", "controllerName", "routeValues", "htmlAttribues") – Joe Apr 22 '12 at 01:29

0 Answers0