Search code examples
asp.net-mvcasp.net-mvc-4actionresult

How to properly call an ActionResult with parameter which return a view


I have this code which returns a view:

public ActionResult Survey(int idProject, string name)
{
    return View(Surveys.Data.Services.Project.GetAllSurveys(idProject));
}

When I call this from client with

@Url.Action("Survey", "Project", new { idProject = project.IdProjet, name = project.Nom })

The url appear with parameters ?idProject=2&name=work which I have been told is not the correct way to work in MVC.

I don't think an ajax call would be of good use here since I return a view to the client.

So how should I call this ActionResult Survey?


Solution

  • Add the following to you RouteConfig.cs file before the default route

    routes.MapRoute(
      name: "ProjectSurvey",
      url: "Project/Survey/{idProject}/{name}",
      defaults: new { controller = "Project", action = "Survey" }
    );