在我的控制器中,我从要更改.resx文件的视图中获取所有值,但是它不起作用-这些值在.resx文件中保持不变。
[HttpPost]
public ActionResult CustimizeSample(FormCollection fc)
{
string formname = Request.Form["formname"];
var lablename = Request.Form["lablename"];
var hintname = Request.Form["hintname"];
var buttonname = Request.Form["buttonname"];
Resources.Resource1.InsertSample_Form_Name.Replace(@Resources.Resource1.InsertSample_Form_Name, formname);
Resources.Resource1.InsertSample_lable_Sample_Name.Replace(@Resources.Resource1.InsertSample_lable_Sample_Name, lablename);
Resources.Resource1.InsertSample_Hint_Name.Replace(@Resources.Resource1.InsertSample_Hint_Name, hintname);
Resources.Resource1.InsertSample_Button_Name.Replace(@Resources.Resource1.InsertSample_Button_Name, buttonname);
return View();
}
答案 0 :(得分:1)
var reader = new ResXResourceReader(@"C:\CarResources.resx");//same fileName
var node = reader.GetEnumerator();
var writer = new ResXResourceWriter(@"C:\CarResources.resx");//same fileName(not new)
while (node.MoveNext())
{
writer.AddResource(node.Key.ToString(), node.Value.ToString());
}
var newNode = new ResXDataNode("Title", "Classic American Cars");
writer.AddResource(newNode);
writer.Generate();
writer.Close();