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.
Try <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?
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