Try our conversational search powered by Generative AI!

Custom route with language

Vote:
 

We are building a cms site where the front end is suppose to load some templates via routes that I have setup. The thing is that I cant seem to get the current language.

I have made a custom route that looks like this: 

routes.MapRoute(name: "templates",
url: "templates/{action}",
defaults: new { controller = "templates", action = "Index" });

My controller then just returns a PartialView. Is it even possible to do it like this or do I have to pass my EPi context some how?

#91396
Oct 03, 2014 16:16
Vote:
 

Could you give us the background and describe the problem you are trying to solve?

I'm not sure you are on the right track here so I would like to know more before we try to help you solve your problem.

#91413
Oct 03, 2014 23:09
Vote:
 

The problem in short is: We need to load templates (modal) via ajax. This template needs to be in the same language as the rest of the site. 

So, I thought I could do a custom route that "deliveres" a template as a partial view. Thought that (since it it the same domain) I could access the current language. 

#91425
Oct 04, 2014 10:19
Vote:
 

Ok.

If you want to create you own routes for API controllers thats fine but you have to provide the language and id of the content object you want to load as parameters to your own controller. EPiServer does not know which language you prefer unless its own default routing is used.

When you type in a friendly url to an EPiServers page a lot of things happens. First it will go through the whole route table, if there is no match EPiServers default route handle will be triggerd. A rater complicated process is triggered to calculate the preferred language from hostname, the first url segment, browser language using different settings. This is nothing you want to implement yourself.

I suggest that you send the id and active language as parameters to your controller in the ajax call.

Then use IContentLoader.Get(new ContentReference(id), new LanguageSelector(lang)) to load the item.

#91429
Oct 04, 2014 14:12
* 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.