0

I am working on Umbraco 7 application. There is one controller in that and i am trying to call its method from my View. But when i call the method from the ActionLink it says method not found. when i verified this from URL it says, it is wrong. Following are the code snippets:

Folling is the MVC line:

   @Html.ActionLink("Send OTP", "Index", "RegisterSurface", new { id = "lnkSendOTP" })

Following is the MVC controller method

public ActionResult Index()
    {
        return View();
    }

I am getting following error on screen, I could not understand the URL formation as well

enter image description here

user2746466
  • 361
  • 5
  • 23

1 Answers1

0

It looks like you're using the wrong overload of the ActionLink method:

public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, object routeValues, object htmlAttributes) {...}

You want to use this one instead:

public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, string controllerName, object routeValues, object htmlAttributes) {...}

Try passing an additional null argument to use the correct overload:

@Html.ActionLink("Send OTP", "Index", "RegisterSurface", null, new { id = "lnkSendOTP" })
Rob Purcell
  • 1,285
  • 1
  • 9
  • 19
  • Have you seen the attached image??? The URL formation looks wrong and thats why it could not find controller method. – user2746466 Jul 04 '16 at 16:23
  • Yes I saw the image. "?Length=15" is being added to the URL because the `ActionLink` method is treating your controller name argument as an `object` instead of a `string` ("RegisterSurface" is 15 characters in length). [This question](http://stackoverflow.com/questions/824279/why-does-html-actionlink-render-length-4) provides a bit more information about the issue. – Rob Purcell Jul 04 '16 at 16:43
  • Tried your solution, still no luck........I do not understand, how the URL is 'Umraco/Surface/RegisterSurface'. It should be 'Umbraco/RegisterSurface/Index'........Otherwise how it will find the controller method. – user2746466 Jul 05 '16 at 12:59
  • One more thing....RouteConfig in my solution is not getting called. Even the global.asax is not getting hit. – user2746466 Jul 05 '16 at 13:47
  • I think 'Surface' is being included because that's just how Umbraco handles routing for surface controllers. Also, 'Index' is being removed from the URL because it is the default action. Could you try renaming your method to something else to see if that helps? If that doesn't work, are there any custom routes in your RouteConfig that might be interfering with Umbraco? – Rob Purcell Jul 05 '16 at 14:05
  • I changed the method name and it worked. Really dont know what is going on. Anyways, thanks Rob.... I will keep posting if i found any other queries... – user2746466 Jul 05 '16 at 16:55