我想重构视图表单代码以避免复制粘贴。但它不起作用。剃刀不允许写
@model System.Linq.Expressions.Expression<Func<TModel, TValue>> expression
和
@Html.Partial("Item", model => model.EmpName)
旧代码,有效:
<tr>
<td class="editor-label" style="border: 0;">
@Html.LabelFor(model=>model.EmpName)
</td>
<td class="editor-field" style="border: 0">
@Html.EditorFor(model=>model.EmpName)
@Html.ValidationMessageFor(model=>model.EmpName)
</td>
</tr>
<tr>
<td class="editor-label" style="border: 0;">
@Html.LabelFor(model=>model.Email)
</td>
<td class="editor-field" style="border: 0;">
@Html.EditorFor(model=>model.Email)
@Html.ValidationMessageFor(model=>model.Email)
</td>
</tr>
重构后不起作用:
项目.cshtml:
@model System.Linq.Expressions.Expression<Func<TModel, TValue>> expression
<tr>
<td class="editor-label" style="border: 0;">
@Html.LabelFor(expression)
</td>
<td class="editor-field" style="border: 0">
@Html.EditorFor(expression)
@Html.ValidationMessageFor(expression)
</td>
</tr>
}
新代码:
@Html.Partial("Item", model => model.EmpName)
@Html.Partial("Item", model => model.Email)
如何让它发挥作用?