C# MVC3数据不是从局部视图收集的
我正在用MVC3编写一个调查应用程序。 我有这门课(简化): 在我看来:C# MVC3数据不是从局部视图收集的,c#,asp.net-mvc-3,partial-views,C#,Asp.net Mvc 3,Partial Views,我正在用MVC3编写一个调查应用程序。 我有这门课(简化): 在我看来: @model Survey // bla bla bla @using (Html.BeginForm()) { @Html.ValidationSummary(true) @Html.Partial("_Respondent", Model.Respondent) } 当我将其发回时,调查对象为空:( _Respondednt局部视图的简化代码: @model Mercer.FITT.Respon
@model Survey
// bla bla bla
@using (Html.BeginForm())
{
@Html.ValidationSummary(true)
@Html.Partial("_Respondent", Model.Respondent)
}
当我将其发回时,调查对象为空:(
_Respondednt局部视图的简化代码:
@model Mercer.FITT.Respondent
<fieldset>
<legend>Respondent Information</legend>
<table>
<tr>
<td>
@Html.LabelFor(model => model.Name)
</td>
<td>
@Html.EditorFor(model => model.Name)
@Html.ValidationMessageFor(model => model.Name)
</td>
</tr>
<tr>
<td>
@Html.LabelFor(model => model.JobTitle)
</td>
<td>
@Html.EditorFor(model => model.JobTitle)
@Html.ValidationMessageFor(model => model.JobTitle)
</td>
</tr>
</table>
</fieldset>
@model Mercer.FITT.responder
受访者信息
@LabelFor(model=>model.Name)
@EditorFor(model=>model.Name)
@Html.ValidationMessageFor(model=>model.Name)
@LabelFor(model=>model.JobTitle)
@EditorFor(model=>model.JobTitle)
@Html.ValidationMessageFor(model=>model.JobTitle)
如果我去掉部分视图,只将部分视图内容复制到主视图中,一切都很好。知道为什么不从部分视图收集数据吗?
也许我应该以不同的方式称之为局部视图
非常感谢。使用EditorTemplate而不是局部视图
@model Survey
@using (Html.BeginForm())
{
@Html.ValidationSummary(true)
@Html.EditorFor(m=>m.Respondent)
}
不要忘记在
EditorTemplates
文件夹中创建appender.cshtml
文件,并将要编辑的应答字段放入其中。您可以发布部分视图“\u appender”的代码吗?
@model Mercer.FITT.Respondent
<fieldset>
<legend>Respondent Information</legend>
<table>
<tr>
<td>
@Html.LabelFor(model => model.Name)
</td>
<td>
@Html.EditorFor(model => model.Name)
@Html.ValidationMessageFor(model => model.Name)
</td>
</tr>
<tr>
<td>
@Html.LabelFor(model => model.JobTitle)
</td>
<td>
@Html.EditorFor(model => model.JobTitle)
@Html.ValidationMessageFor(model => model.JobTitle)
</td>
</tr>
</table>
</fieldset>
@model Survey
@using (Html.BeginForm())
{
@Html.ValidationSummary(true)
@Html.EditorFor(m=>m.Respondent)
}