假设这些类\枚举:
public enum Test
{
MyTest1 = 0,
MyTest2,
MyTest3,
}
public class Model
{
public Dictionary<Test, string> TestDictionary { get; set; }
public Dictionary<string, string> StringDictionary { get; set; }
public string Other { get; set; }
public Model()
{
TestDictionary = new Dictionary<Test, string>();
StringDictionary = new Dictionary<string, string>();
}
}
这种形式:
<form action="/Home/Test" method="post">
<input type="hidden" name="Model.TestDictionary[MyTest1]" value="myval" />
<input type="hidden" name="Model.StringDictionary[mykey]" value="myval" />
<input type="hidden" name="Model.StringDictionary[mykey2]" value="myval2" />
<input type="hidden" name="Model.Other" value="works" />
<button type="submit">Submit</button>
</form>
而这个动作:
public ActionResult Test(FormCollection formCollection)
{
Model model = new Model();
TryUpdateModel(model, "Model");
return Redirect("Index");
}
Model.StringDictionary
get 更新成功。
我无法获得Model.TestDictionary
更新。
我尝试了多种方法,例如将输入名称更改为Test.MyTest1
但无法使其正常工作。
我的输入应该如何看起来像我想要填充的 id Model.TestDictionary
?