-1
  1. 我想知道如何在 mvc3 asp.net C# 中添加复选框。我正在使用 Aspx 视图引擎。

  2. 我必须添加多个复选框,并且必须保存选择为 true 的复选框的数据。

我怎样才能做到这一点?

4

1 回答 1

2

这是一个例子:

在您的“模型类”中:

public class TennisCourt
{
    [Key]
    public int ID { get; set; }

    [Display(Name = "Extérieur ?")]//=Outside in french
    [Column("Outside")]
    public bool Outside { get; set; }
}

在您的“查看索引”中

@model IEnumerable<TennisOnline.Models.TennisCourt>

@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Gestion des Courts</h2>

<p>
@Html.ActionLink("Create New", "Create")
</p>
<table>
<tr>
    <th>
     Id    
    </th>
    <th>
        Outside ?
    </th>

    <th></th>
</tr>

@foreach (var item in Model) {
<tr>
    <td>
       @Html.DisplayFor(modelItem => item.ID)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.Outside)
    </td>

    <td>
        @Html.ActionLink("Edit", "Edit", new { id=item.ID }) |
        @Html.ActionLink("Details", "Details", new { id=item.ID }) |
        @Html.ActionLink("Delete", "Delete", new { id=item.ID })
    </td>
</tr>
}

结果如下:

在此处输入图像描述

于 2012-03-15T10:33:01.073 回答