Gerald
Gerald

Reputation: 1083

Custom controller for the layout.cshtml

I have an MVC website which I wanted to implement a globalization/localization. On my _Layout.cshtml, I have a dropdown which have the languages I supported. When a user selected a language on that dropdown, it should automatically post to the server then render the new language.

Is it possible that I create a specific custom controller for the _Layout.cshtml only? If yes, how? If no, is there any possible way or approach I can make?

Thanks in advance!

Upvotes: 0

Views: 284

Answers (1)

SLaks
SLaks

Reputation: 887453

You should move that to a child action, then call the child action from the layout view.

You can make the form POST to a separate action (in a controller shared with the child action) that sets the cookie / session / DB property, then redirects back to the original URL (via Request.UrlReferrer or from a hidden model-bound field).

Upvotes: 2

Related Questions