Je suis nouveau à asp.net mvc.J'ai une liste de cases à cocher et je veux quand les cases à cocher sont sélectionnées une nouvelle liste de cases à cocher sélectionnées sont affichées. mon code Product.cs code:comment être sélectionné case à cocher dans asp.net en utilisant le cadre d'entité
public class Product
{
public int ProductID { get; set; }
public string ProductName { get; set; }
public int Price { get; set; }
public bool Checked { get; set; }
public virtual ICollection<Purchase> Purchases { get; set; }
}
Mon point de vue:
<h2>Product Lists</h2>
@using (Html.BeginForm())
{
<table class="table">
<tr>
<th>
Product ID
</th>
<th>
Product Name
</th>
<th>
Price
</th>
<th></th>
</tr>
@for (var i = 0; i < Model.Count(); i++)
{
<tr>
<td>
@Html.DisplayFor(x => x[i].ProductID)
</td>
<td>
@Html.DisplayFor(x => x[i].ProductName)
</td>
<td>
@Html.DisplayFor(x => x[i].Price)
</td>
<td>
@Html.CheckBoxFor(x => x[i].Checked, new { Style = "vertical-align:3px}" })
</td>
</tr>
}
</table>
<input type="submit" value="Purchase" class="btn btn-default" />
}
Ceci est mon contrôleur code.I voulez, quand les cases à cocher sont sélectionnées dans une nouvelle page les cases à cocher sélectionnées sont affichées. mon ActionResult:
public ActionResult Index()
{
return View(db.Products.ToList());
}
[HttpPost]
public ActionResult Index(List<Product> list)
{
return View(list);
}
@using (Html.BeginForm())
{
<table class="table">
<tr>
<th>
Product ID
</th>
<th>
Product Name
</th>
<th>
Price
</th>
<th></th>
</tr>
@for (var i = 0; i < Model.Count(); i++)
{
<tr>
<td>
@Html.DisplayFor(x => x[i].ProductID)
</td>
<td>
@Html.DisplayFor(x => x[i].ProductName)
</td>
<td>
@Html.DisplayFor(x => x[i].Price)
</td>
<td>
@Html.CheckBoxFor(x => x[i].Checked, new { Style = "vertical-align:3px}" })
</td>
</tr>
}
</table>
Référez [cette réponse] (http://stackoverflow.com/questions/29542107/pass-list-of-checkboxes-into-view-and -extraire -enumerable/29554416 # 29554416) pour un exemple –
s'il vous plaît aidez-moi plus .. Je ne peux pas résoudre mon problème – balouchi
Quel problème? Qu'est-ce qui ne fonctionne pas? Quelles erreurs obtenez-vous? –