November Happy Hour will be moved to Thursday December 5th.

CurrentPage is null in Actions

Vote:
 

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

Delete

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");

#186479
Dec 20, 2017 13:45
Vote:
 

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");

#186488
Dec 20, 2017 15:17
Vote:
 

Regarding routing in Episerver vs MVC, I think this is a good blog post: http://jondjones.com/learn-episerver-cms/episerver-developers-guide/episerver-routing/episerver-7-routing-for-dummies

#186489
Dec 20, 2017 15:39
Vote:
 

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.

#186499
Dec 21, 2017 0:14
Vote:
 

I solved it using node like this

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

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

#186510
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.