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?
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.
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
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.
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.
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
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 actionis working on a reply...