Html.ActionLink in Litium 6 MVC

How do I use Html.ActionLink i MVC?
I want to reach controller “Product” with the method “DownloadPdf”. (public ActionResult DownloadPdf(string id){})

I have tried this code in the .cshtml “@Html.ActionLink(“Download PDF”, “DownloadPdf”, “Product”, new { id = Model.ProductItem.Id }, null)”
But that only generates /.DownloadPdf?id=123
I want to generate /Product/DownloadPdf/123 OR add .DownloadPdf?id=123 to the end of the url, I can reach the method with both urls, but the ActionLink is generating wrong url.

Litium version: 6

<a href="@Url.Action(Model.LogoutPage, new { action = "Logout" })" class="logout" title="@Html.WebSiteString("LoginLogOutButton")">@Html.WebSiteString("FrameworkLogOut")</a>
(a sample from Accelerator Views\MypageB2B\Index.cshtml).

In standard ASP.NET MVC the delimiter slash (/) is used between the controller and action name or parameters, when using ASP.NET MVC in Litium the first delimiter is changed to a dot (.). The reason is that the url parser needs to know where the url is ending and where the action (or parameter) is starting.


I tried
<a href="@Url.Action(“DownloadPdf”, “Product”, new { id = Model.ProductItem.Id })" class=“test”>Download PDF

But I still get /.DownloadPdf?id=“123”, since the Action removes the original url, any way to keep the original url or can i create a new route for this?

Use the Action()-method with the signature from my previous the example to use the extensionmethod provided by Litium.

Like this? It’s still the same result
<a href="@Url.Action(CurrentState.Current.Page, new { action = “DownloadPdf” })">Download Pdf

You should be calling the Action method in Litium.Web.Mvc.UrlHelperExtension.

Also add your ID: <a href="@Url.Action(CurrentState.Current.Page, new { action = “DownloadPdf”, Id = Model.ProductItem.Id })">

If you do what does your url look like?

Thanks, that works better, but now i got another problem, when i am in ProductController and use CurrentState.Current.Page i get the startpage? And i can’t get any page that is a “ProductPage”

On a productpage you can pass the current baseproduct/variant into your action using model binding.

For automatic mapping of current entity (baseproduct, page etc.) from the input parameters in the request the word current should be used in the name, for example Page currentPage. When the parameter name starts with current the parsing of input parameters in the request is ignored, instead the parameter is only assigned from the values that is extracted from the url-parsing.

Thanks, but why are the ProductController mapped to startpage? This is a clean litium installation so i don’t think we have changed anything about that.

I can’t reach the methods in productController since there is no page for that controller

CurrentPage points to the current page in CMS, since products do not have CMS-pages you get the StartPage.

The accelerator has added a route that let you access controllers using site.axd so you should be able to write a url using that pattern:

   "ControllerDirect", // Route name
   "site.axd/{controller}/{action}/{id}", // URL with parameters
   new {action = "Index", id = UrlParameter.Optional} // Parameter defaults
).DataTokens["SkipAutoLayout"] = true;

From Litium.Accelerator.MVC/App_Start/RouteConfig.cs

Yes, I guess thats the only way, i was hoping for some nice way of using the Actionlink but I guess I have to hard code a link.