c# 4.0 - Cannot figure out which route between two same method, one without parameter and one with -


in controller, have 2 method :

 public actionresult nouvelledemande()     {          int numdossier = structuredata.donnenumdossier((string)session["utilisateur"], (string)session["motdepasse"]);         list<contact> listecontacts = structuredata.donnelistecontact(numdossier);         if (listecontacts != null)         { viewbag.listecontacts = listecontacts; }         else         { viewbag.listecontacts = null; }         return view();     }      public actionresult nouvelledemande(demandeassistance nouvelledemande)     {         bool demandeenregistree = nouvelledemande.enregistrerdemande();         if (demandeenregistree)         {              return index();         }         else         {             viewbag.error = "la demande n'a pas été enregistrée !";             return view();         }     } 

so when want display view() associated method, call first one. in view(), have form when submitted, send object demandeassistance second method. in routes config, did :

routes.maproute(             name: "nouvelledemande",             url: "{controller}/{action}",             defaults: new { controller = "accueil", action = "nouvelledemande" }         );          routes.maproute(             name: "ajouternouvelledemande",             url: "{controller}/{action}/{id}",             defaults: new { controller = "accueil", action = "nouvelledemande", id = urlparameter.optional }         ); 

but shows me error when want display view saying there misunderstanding between these 2 routes. did wrong ?

i manage find out missing if don't understand why. i've put :

// post : /accueil/nouvelledemande     [httppost] 

upon method contains parameter, follows:

// post : /accueil/nouvelledemande     [httppost]     public actionresult nouvelledemande(demandeassistance nouvelledemande)     {         bool demandeenregistree = nouvelledemande.enregistrerdemande();         if (demandeenregistree)         {              return index();         }         else         {             viewbag.error = "la demande n'a pas été enregistrée !";             return view();         }     } 

maybe interested have time explain why works actually.


Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

jquery - How would i go about shortening this code? And to cancel the previous click on click of new section? -