3

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?

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Mathieu
  • 113
  • 1
  • 2
  • 9

2 Answers2

2

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

If you want to have a url like Survey/Project/2/work, then you need to modify your route value like,

 routes.MapPageRoute("Default",
    "{controller}/{action}/{idProject}/{name}",
    "new { yourcontroller, youraction, UrlParameter.Optional, UrlParameter.Optional");
Venkatesh
  • 1,204
  • 1
  • 10
  • 18