Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 如何在MVC中设置可重用的文本字符串_Html_Asp.net Mvc_Web_Razor - Fatal编程技术网

Html 如何在MVC中设置可重用的文本字符串

Html 如何在MVC中设置可重用的文本字符串,html,asp.net-mvc,web,razor,Html,Asp.net Mvc,Web,Razor,如何在MVC中设置可重用的文本字符串 例如:我有一个文本需要在几页中使用,我将如何设置 在PHP中类似于 $lang = array ( 'getpassword' => 'Forget Password', 'login_guest' => 'No Account?', 'new_password' => 'New Password', 'new_password_confirm' => 'Comfirm Password', ); 您

如何在MVC中设置可重用的文本字符串

例如:我有一个文本需要在几页中使用,我将如何设置

在PHP中类似于

$lang = array (
    'getpassword' => 'Forget Password',
    'login_guest' => 'No Account?',
    'new_password' => 'New Password',
    'new_password_confirm' => 'Comfirm Password',
);

您可以在视图中声明字典,也可以在视图中使用

 @{
    var lang= new Dictionary<string, string>();
    lang.Add("getpassword", "Forget Password");
    lang.Add("login_guest" , "No Account?");
    lang.Add("new_password", "New Password");
    lang.Add("new_password_confirm", "Confirm Password");
                
                
    var item = lang.Where(x=>x.Key=="getpassword").Select(p => new Dictionary<string, string>() { {p.Key, p.Value }});
    }
@{
var lang=新字典();
lang.Add(“获取密码”、“忘记密码”);
lang.Add(“登录\客人”,“没有帐户?”);
lang.Add(“新密码”、“新密码”);
lang.Add(“新密码”、“确认密码”);
var item=lang.Where(x=>x.Key==“getpassword”)。选择(p=>newdictionary(){{p.Key,p.Value});
}
或者,您可以创建一个局部视图来声明此字典,并且可以在布局中包含该局部视图,以便可以在任何地方访问它


请参阅

对不起,我可以知道如何使用它吗?因为在PHP中只要{lang.getpassword}就可以使用var item=lang.Where(x=>x.Key==“getpassword”).Select(p=>newdictionary(){p.Key,p.Value});您只需更改where子句中的键