Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 使用助手方法和编辑器模板呈现3列复选框表_Asp.net Mvc_Mvc Editor Templates_Helpermethods - Fatal编程技术网

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>