【发布时间】:2015-02-27 17:23:46
【问题描述】:
进一步了解here 建议的解决方案,我尝试过但没有成功 - 我想知道 razor 如何计算出呈现强类型化的局部视图?我按照建议做了,但感觉好像没有正确绑定并且缺少某些东西。
我的“子”模型:
public class Cohort
{
public bool ukft { get; set; }
public bool ukpt { get; set; }
...etc
}
我的强类型部分视图:
@model Models.Cohort
@Html.RadioButtonFor(model => Model.ukft, true) <span style="margin-right:8px;">Yes</span>
@Html.RadioButtonFor(model => Model.ukft, false) <span>No</span> <br />
我的主模型(其中包含 Cohort 对象列表):
public class OptOut
{
public int optOutID { get; set; }
public bool hasOptedOut { get; set; }
public List<Cohort> list { get; set; }
public OptOut()
{
List<Cohort> list = new List<Cohort>();
list.Add(new Cohort());
list.Add(new Cohort());
list.Add(new Cohort());
list.Add(new Cohort());
this.list = list;
}
}
然后是我的html:
@model Models.OptOut
@using (Html.BeginForm("OptedOut", "Home"))
{
//this should supposedly figure out to render a partial view for each element in the list
@Html.EditorFor(model => model.list)
<div class="form-group" style="margin-top:25px;">
<input id="confirm" type="submit" value="Confirm" class="btn btn-success btn-lg"/>
</div>
}
【问题讨论】:
标签: c# asp.net-mvc razor view model