Virtual Happy Hour this month, Jun 28, we'll be getting a sneak preview at our soon to launch SaaS CMS!

Try our conversational search powered by Generative AI!

CurrentPage is null in Actions


So I have a controller like this

public class BookmarksPageController : PageController
        public ActionResult Index(BookmarksPage currentPage)
            /* Implementation of action. You can create your own view model class that you pass to the view or
             * you can pass the page type for simpler templates */

            IEnumerable bookmarksFolders = BookmarksFolder.GetFoldersByEmail();

            var model = new BookmarksPageViewModel(currentPage, bookmarksFolders);
            return View(model);
         public ActionResult RemoveBookmark(BookmarksPage currentPage)
            // I want to do something here and redirect to the Index action

            return Redirect("/en/bookmarks");

The issue is that my currentPage in RemoveBookmark action is always null.

I am calling it this way


I think it is because it is routing like mvc and not through the episerver routing. How to solve this? 

Ideally I would like to have currentPage in RemoveBookmark action to be not null but if that is not possible I would at least like to throw user to the Index properly so that I don't have to hard code the url like Redirect("/en/bookmarks");

Dec 20, 2017 13:45

I would rather use the @Html.ActionLink if you want to create a link to a method in a controller and pass data to it.

Same goes for redirect I would use: RedirectToAction("Index", "NewController");

Dec 20, 2017 15:17

Regarding routing in Episerver vs MVC, I think this is a good blog post:

Dec 20, 2017 15:39

url of incoming request does not guarantee that particular page controller will be hit. imagine that you can create zillions of instances of that particular page (content) type under the start page: /page1/, /page2/, /page3/ etc. so how episerver knows that request to all these 3 url should invoke exactly the same page controller? it does by not direct mapping of url to page type but instead actually "looks" who is sitting under that url (what content type) and then does black magic with resolving which handler will be invoked (because there might be complex inheritance chain between the types). so it's not 1:1.

Dec 21, 2017 0:14

I solved it using node like this

@Url.Action("RemoveBookmark", new { node = Model.CurrentPage.ContentLink, id = i.Id.ToString() })
Dec 21, 2017 7:26

one way to get around these hustles with controllers, actions and content links would be to use `Geta.EPi.Extensions.QueryString.QueryStringBuilder` ;)

Dec 21, 2017 11:14
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.