简体   繁体   中英

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!

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM