有没有办法将值传递给Dictionary<>类型的属性?从一个视图中使用Html.BeginForm帮助方法?
模型
public class LogicTest
{
public int LogicTestID { get; set; }
public string SingleString { get; set; }
public Dictionary<string, string> SimpleDictionary { get; set; }
public Dictionary<string, Dictionary<string, string>> NestedDictionary { get; set; }
}
ATM我尝试这样的事情(显然没有太大的成功)
@model TestNamespace.Models.LogicTest
@using (Html.BeginForm("CreateLogicTest", "LogicTest"))
{
@Html.LabelFor(n => n.SingleString)<br />
@Html.EditorFor(n => n.SingleString)<br />
@Html.LabelFor(n => n.SimpleDictionary)<br />
@Html.Label("Simple Dictionary Item 1")
@Html.EditorFor(n => n.SimpleDictionary["key1"])
@Html.Label("Simple Dictionary Item 2")
@Html.EditorFor(n => n.SimpleDictionary["key2"])
@Html.Label("Simple Dictionary Item 3")
@Html.EditorFor(n => n.SimpleDictionary["key3"])
<button type="submit">Submit</button>
}
答案 0 :(得分:0)
您必须在控制器操作中创建类的实例。然后返回该类的视图。