In my controller, I have two method like that :
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 I want just to display the view() associated to the method, I call the first one. In the view(), I have a form which when submitted, send an object DemandeAssistance to the second method. In the routes config, i did that :
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 it shows me an error when I want just to display the view saying that there is a misunderstanding between these two routes. What did I do wrong ?