我的 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_affectation
是1
和2
。
为什么会发生这种情况?我该如何解决?