有没有办法可以将复选框添加并绑定到我的 MVC 表

问题描述 投票:0回答:3

我正在尝试添加一个复选框,以便我可以从列表中选择一行,然后使用该行生成一封信。 我想知道如何添加一个复选框并将其绑定到我尝试过使用类似以下内容的几种方法的数据:

checkbox(m => m[i].Lesson)

但是它永远不会接受括号中的 i 并出现错误。下面是我当前课程模型的索引布局。

这是课程索引:

@model IEnumerable<FinalMusicApp.Models.Lesson>

@{
    ViewBag.Title = "Index";
}


<h2>Lessons</h2>

<p>
    @Html.ActionLink("Create New", "Create")
</p>

@using (Html.BeginForm("Index", "Students", FormMethod.Get))
{
    //Search options
    <b>Search Options: </b> @Html.RadioButton("Option", "Instrument")<text>Instrument</text>@Html.RadioButton("Option", "Tutor")<text>Tutor</text>@Html.RadioButton("Option", "Term")<text>Term</text>@Html.TextBox("Search")
    <input type="submit" name="submit" value="Search" />
}



<form method="post">
    <table class="table">
        <tr>
            <th>
                @Html.DisplayNameFor(model => model.IsChecked)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.LessonDate)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.LessonTime)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Duration.TimeTaken)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Instrument.InstrumentName)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Letter.Paid)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Student.FullName)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Tutor.TutorName)
            </th>
            <th>
                CRUD
            </th>
            <th>
                Make a letter
            </th>
        </tr>


        @foreach (var item in Model)

        {
            <tr>
                <td>
                    @Html.CheckBoxFor(modelItem => item.IsChecked)
                </td>

                <td>
                    @Html.DisplayFor(modelItem => item.LessonDate)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.LessonTime)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Duration.TimeTaken)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Instrument.InstrumentName)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Letter.Paid)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Student.FullName)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Tutor.TutorName)
                </td>
                <td>
                    @Html.ActionLink("Edit", "Edit", new { id = item.LessonId }) |
                    @Html.ActionLink("Details", "Details", new { id = item.LessonId }) |
                    @Html.ActionLink("Delete", "Delete", new { id = item.LessonId })

                </td>
                <td>
                    @Html.ActionLink("Generate Letter", "Create", "Letters")
                </td>


            </tr>
        }

    </table>

</form>
asp.net-mvc asp.net-core model-view-controller
3个回答
0
投票

我正在尝试添加一个复选框,以便我可以从列表中选择一行

你想要像下面这样的东西吗?

在视图中添加一个复选框,例如我在模型中使用属性 CourseName ,您可以使用您的属性:

 @Html.CheckBox("CourseName", new { value = item.CourseName })
 @Html.DisplayFor(modelItem => item.CourseName)

然后在控制器中,我们可以获取 CourseName 值,并根据 CourseName 获取其他属性值,但是我们需要再次加载列表,我们无法将完整列表从视图发送到控制器:

var courserow = model.FirstOrDefault(m => m.CourseName == CourseName);

结果:


0
投票

要将一条线投影到三维空间中的平面上,可以使用以下公式。让我们考虑一条由点给出的线 � 直线上的 P 和方向向量 � v 为行。该行可以通过参数进行参数化 � t:

线路: � ( � )

� + � ⋅ � 直线: r(t)=P+t⋅v

现在,让我们考虑一个由点给出的平面 � 平面上的 Q 和法向量 � n 为飞机。该平面可以用以下方程描述:

飞机: � ⋅ ( � - � )

0 平面:n⋅(r−Q)=0

直线在平面上的投影,表示为 项目 ( � ) proj(r),可以使用以下公式计算:

项目 ( � )

� + ( ( � - � ) ⋅ � � ⋅ � ) ⋅ � 投影(r)=Q+( v·n (P−Q)⋅n )·v

这里:

� r 是线上的一点。 � P是直线上的一点。 � v 是直线的方向向量。 � Q是平面上的一点。 � n 是平面的法向量。 ⋅ ⋅ 表示点积。 该公式涉及点积和标量乘法等向量运算。它提供了平面上最接近给定线的点,形成线在平面上的投影。


-2
投票
© www.soinside.com 2019 - 2024. All rights reserved.