0

我的 asp.net mvc 应用程序有错误。我有这样的看法:

@if (Model == null || Model[1] == null || Model[1].Count == 0) 
{
    <label>Pas de demande</label>
                         }
else{
    int i = 1;
    string s = "";
    <form action="\Travail\Validation_Reservation" method="post">
@foreach( Planning.Models.Affectation v in Model[1]){
    if (v.Periode == 1) { s = "matinale"; }
    else { s = " Après midi"; }
    int a = v.Id_affectation; 
     <div><h5 style="color:blue">@i / Demande de reservation de vehicule @veh.Matricule : le @v.Date_affectation , la periode @s</h5>
    <input type="hidden" name="id" value="@a" />
    <input type="submit" name="btn" value="valider" />
   <input type="submit" name="btn" value="refuser" /></div>
    <br />
    i++;
     }
        </form>

这个动作:

public ActionResult Validation_Reservation() {
            string btn = Request.Params["btn"];
            string id_string = Request.Params["id"];
            int id_affectation = int.Parse(id_string);
            Owner resp = new Owner();
            if (btn == "valider") {
                resp.Accepter_Reservation(id_affectation);
                return RedirectToAction("Notification");
                  }
            resp.Refuser_Reservation(id_affectation);
            return RedirectToAction("Notification");
         }

我的问题是在行string id_string = Request.Params["id"];id_string作为值1,2,但整数的值id_affectation12

为什么会发生这种情况?我该如何解决?

4

1 回答 1

0

我找到了这个解决方案,我必须更改 和 的顺序form才能loop获得独特的id

@foreach( Planning.Models.Affectation v in Model[1]){
<form action="\Travail\Validation_Reservation" method="post">

    if (v.Periode == 1) { s = "matinale"; }
    else { s = " Après midi"; }
    int a = v.Id_affectation; 
     <div><h5 style="color:blue">@i / Demande de reservation de vehicule @veh.Matricule : le @v.Date_affectation , la periode @s</h5>
    <input type="hidden" name="id" value="@a" />
    <input type="submit" name="btn" value="valider" />
   <input type="submit" name="btn" value="refuser" /></div>
    <br />
    i++;

        </form>
}
于 2013-07-23T14:02:59.120 回答