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

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

我该怎么做?

+0

你使用实体框架?你想将数据保存在数据库中吗? – Razor 2012-03-15 09:48:28

+0

@Francesco是的,我想将它保存在数据库中,我使用实体框架 – Dip 2012-03-15 10:20:39

+0

那么,你使用“代码优先”与“模型类”? – Razor 2012-03-15 10:25:43

回答

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> 
} 

下面是结果:

enter image description here