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

Controller Questions that i don't understand

Vote:
 

I have a search controller that takes in the standard PageType SearchController(SearchPage currentPage).  My question is, how do I wire up this controller to acces this base on a url
SearchController(SearchPage currentPage, string q, int Page)
so my url looks as such "/search/searchtermhere/1".  I am just really uncertain how to accomplish.  Thanks in advance.

#63811
Nov 30, 2012 3:54
Vote:
 

There some ways of making this work. Here is one example:


In an initialization module, add the following in the "Initialize(InitializationEngine context)" method:

            const string segments = "{language}/{node}/{action}/{search}/{page}";
            var defaults = new {action = "index", search = "", page = 1};
 
            RouteTable.Routes.MapEnterpriseRoutes("searchInsideRoot", segments, defaults);
            RouteTable.Routes.MapPageRootRoute("searchOutsideRoot", segments, defaults);

Now you can have controller action looking like this:
public ActionResult Index(SearchPage currentPage, string search, int page)
        {
            var model = new ViewModel();
            return View(model);
        }

And youre url can be: /Search/index/SomeSearchQuery/4/

Hope this helps.
#63816
Nov 30, 2012 9:44
Vote:
 

Hey Jonas,  I ahve tried and tried to get this to work and for some reason, I am unable to use the above code.  If i don't inherit from the Controller<T> I can get this to work, but as soon as I inherit, it goes all whonky.  Yeh, thats right, I said whonky :).  Am I missing something.  I doing DI for the controllers like in the preview version, do you think this has something to do with it?

#63850
Nov 30, 2012 20:57
Vote:
 

I don't know why id doesnt work for you. Does it work if you only have an empty contructor?

#64019
Dec 07, 2012 10:53
Vote:
 

Hi,

I have the same problem. Did you get it to work. I will be very happy if you will share it with me.

Thanks!

// Andreas

#64776
Jan 09, 2013 16:48
Vote:
 

I am using a very similar functionality for a pager on my listing page.

This is how my code looks like, perhaps it helps you.

    public class ListingPageController : PageController<ListingPage>
    {

        public ActionResult Index(ListingPage currentPage, int? page)
        {
            var viewModel = new ListingPageViewModel();
            AutoMapper.Mapper.Map(currentPage, viewModel);

            // not important
            
            return View(viewModel);
        }
    }

Please note that I have a nullable int in Index, because my edit view doesn't work if it's not nullable.

This is how a part of the view looks like:

@Html.ActionLink(page.Nr.ToString(CultureInfo.InvariantCulture), "Index", new { page = page.Nr })

And this is the RouteModule:

    [ModuleDependency(typeof(EPiServer.Web.InitializationModule))]
    public class RouteModule : IInitializableModule
    {

        public void Initialize(InitializationEngine context)
        {
            const string segments = "{language}/{node}/{action}/{page}";
            var defaults = new { action = "Index", page = 1 };

            RouteTable.Routes.MapEnterpriseRoutes("pageInsideRoot", segments, defaults);
            RouteTable.Routes.MapPageRootRoute("pageOutsideRoot", segments, defaults);
        }

        public void Preload(string[] parameters)
        {
        }

        public void Uninitialize(InitializationEngine context)
        {
        }
    }

Perhaps you can try and see if this works for you.

#64879
Jan 14, 2013 15:04
Vote:
 

Excuse my ignorance but why am I not seeing the MapEnterpriseRoutes on the RouteTable.Routes namespace?

#64883
Jan 14, 2013 15:38
Vote:
 

Have you included using EPiServer.Web.Routing; ? What is your version of EPiServer 7?

#64884
Jan 14, 2013 15:39
Vote:
 

Yes Ma'am, i am using the latest version of EPiServer 7.  Let me play around with this more and I will get back to you shortly.

#64885
Jan 14, 2013 15:41
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* 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.