Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Dan Mac 12 posts 32 karma points
    Mar 14, 2013 @ 00:23
    Dan Mac
    0

    Umbraco 4.11.5 eviqualent of Url.Action?

    Hi,

    I am using Url.Action in my Razor View like below. However the url returned is always empty. Is this the correct way to link to an RenderMvcController action method in the razor view? Or is there an umbraco helper method?

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<MyCustomViewModel>

    ....

    @
    {
    var url = Url.Action("SearchAction", "SearchController", new RouteValueDictionary(new { pageNumber = Model.PageNumber}))
    }

    Thanks,
    Dan

  • Andreas Iseli 150 posts 427 karma points
    Mar 18, 2013 @ 09:25
    Andreas Iseli
    0

    I assume your controller inherits from SurfaceController?

    The problem is that the Umbraco core must do an internal redirect to be able to post your mvc data onto the corrent controller in the correct page context. When using a form (Html.BeginUmbracoForm) it always adds a hidden value containing the route values for this.

    I had a quick look at the core code but could not find an appropriate overload for the Url.Action. Perhaps someone else knows more about this? Else I can only suggest to either use a form with a button or use a form and append the hidden value (uformpostroutevals) to your URL action which must point to the current page.

    Regarding the search you may also use a standard MvcController on a reserved URL. Then you don't have the problematic with the route values.

  • Tommy Albinsson 121 posts 254 karma points
    Mar 27, 2013 @ 15:19
    Tommy Albinsson
    0

    This would be nice to know. I also have not figured out how to use @Url.Action("actionName", "controller") yet. It allwas returns null at the moment.

  • Anja Marx 1 post 21 karma points
    Jun 21, 2013 @ 15:42
    Anja Marx
    0

    Hi,

    I had the same issue and found the answer here: http://stackoverflow.com/questions/2808075/asp-net-mvc-route-to-url. You can obtain the URL through:

    RouteValueDictionary values = new RouteValueDictionary(new { controller = "ControllerName", action = "ActionName" });

    RequestContext context = new RequestContext(HttpContext, RouteData);

    string url = RouteTable.Routes.GetVirtualPath(context, values).VirtualPath;

    Hope this helps,

    Anja

  • Vijayendra Bose 2 posts 71 karma points
    Jul 22, 2016 @ 01:08
    Vijayendra Bose
    0

    Hi guys,

    Just wanted to mention that as of today, with Umbraco 7, you could now use

    @Url.SurfaceAction<mySurfaceController>("actionName") to generate a link to a surface action

Please Sign in or register to post replies

Write your reply to:

Draft