Asp.net mvc 使用助手方法和编辑器模板呈现3列复选框表
以下代码取自本教程的讲师编辑视图:Asp.net mvc 使用助手方法和编辑器模板呈现3列复选框表,asp.net-mvc,mvc-editor-templates,helpermethods,Asp.net Mvc,Mvc Editor Templates,Helpermethods,以下代码取自本教程的讲师编辑视图: @{ int-cnt=0; 列出课程=ViewBag.courses; foreach(课程中的var课程){ 如果(cnt++%3==0){ @: } @: @course.CourseID@:@course.Title @: } @: } 此代码显示以下课程复选框: 使用助手方法和编辑器模板来实现相同的结果会更加优雅,对吗?e、 g: 查看 <div class="editor-field"> <
@{
int-cnt=0;
列出课程=ViewBag.courses;
foreach(课程中的var课程){
如果(cnt++%3==0){
@:
}
@:
@course.CourseID@:@course.Title
@:
}
@:
}
此代码显示以下课程复选框:
使用助手方法和编辑器模板来实现相同的结果会更加优雅,对吗?e、 g:
查看
<div class="editor-field">
<table style="width: 100%">
@Html.EditorFor(model => model.courses)
</table>
</div>
@EditorFor(model=>model.courses)
编辑器模板
@model AssignedCourseData
@using ContosoUniversity.ViewModels
<tr>
<td>
@Html.HiddenFor(model => model.CourseID)
@Html.CheckBoxFor(model => model.Assigned)
@Html.DisplayFor(model => model.CourseName)
</td>
</tr>
@model AssignedCourseData
@使用ContosoUniversity.ViewModels
@Html.HiddenFor(model=>model.CourseID)
@CheckBoxFor(model=>model.Assigned)
@DisplayFor(model=>model.CourseName)
但这不会将复选框呈现为3列表。有人能建议怎么做吗
@model AssignedCourseData
@using ContosoUniversity.ViewModels
<tr>
<td>
@Html.HiddenFor(model => model.CourseID)
@Html.CheckBoxFor(model => model.Assigned)
@Html.DisplayFor(model => model.CourseName)
</td>
</tr>