对于layout.cshtml定制控制器 [英] Custom controller for the layout.cshtml
问题描述
我有一个MVC网站,我想要实现全球化/本地化。在我的 _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.
难道我创建一个特定的定制控制器的 _Layout.cshtml
只?如果是的话,怎么样?如果没有,是否有任何可能的方式或办法,我可以做什么呢?
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?
在此先感谢!
推荐答案
您应该移动,为了孩子的动作,然后调用从布局来看孩子的行动。
You should move that to a child action, then call the child action from the layout view.
您可以使表单POST到一个单独的操作(在与孩子的动作共享的控制器)的设置cookie /会话/ DB属性,然后重定向回原始URL(通过请求。 UrlReferrer
或隐藏模型绑定字段)。
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).
这篇关于对于layout.cshtml定制控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!