问:我如何获得此ViewData? @ViewData["MyCustomCollection"]["MyParam1"]
它会返回错误Cannot apply indexing with [] to an expression of type 'object'
查看(MyCustomCollecion有[UIHint("MyCustomEditor")]
@Html.EditorFor(model => model.MyCustomCollection, new
{
MyCustomCollection = new
{
Param1 = "MyParam1"
Param2 = "MyParam2"
}
})
MyCustomEditor
(...)
<span>@ViewData["MyCustomCollection"]["MyParam1"]<span>
<span>@ViewData["MyCustomCollection"]["MyParam2"]<span>
(...)
重要提示:我需要将MyCustomCollection
设为父级。我不能这样做:
@Html.EditorFor(model => model.MyCustomCollection, new
{
Param1 = "MyParam1"
Param2 = "MyParam2"
})