c# - Getting a false value of integer from view in razor -


i have error in asp.net mvc application. have view :

@if (model == null || model[1] == null || model[1].count == 0)  {     <label>pas de demande</label>                          } else{     int = 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 = 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> 

and action:

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");          } 

my problem in line string id_string = request.params["id"]; id_string takes value 1,2 values of integer id_affectation 1 , 2.

why happens? how can fix it?

i find solution, have change order of form , loop unique 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 = 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> } 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -