Don't miss out Virtual Happy Hour this Friday (April 26).
Don't miss out Virtual Happy Hour this Friday (April 26).
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.
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?
I don't know why id doesnt work for you. Does it work if you only have an empty contructor?
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
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.
Excuse my ignorance but why am I not seeing the MapEnterpriseRoutes on the RouteTable.Routes namespace?
Have you included using EPiServer.Web.Routing; ? What is your version of EPiServer 7?
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.
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.