1

Using ASP MVC, I have the following Action link,

<a href="@Url.Action("Page", "Content", new { publicationId = publication.PublicationId })">@publication.Title</a>

for the controller action

public ActionResult Page(int publicationId)

Which works, but the URL looks like this

Content/Page?publicationId=129

and I prefer it to look like

Content/Page/129

Is there anyway to make that change?

1 Answer 1

1

You need to define a route to use your publicationId parameter for your Content controller In your App_Start\RouteConfig.cs add above the Default route:

routes.MapRoute(
    name: "ContentPage",
    url: "Content/{action}/{publicationId}",
    defaults: new { controller = "Content", action = "Page", publicationId = UrlParameter.Optional }
);

If you want it to be specific only to the Page action:

routes.MapRoute(
    name: "ContentPage",
    url: "Content/Page/{publicationId}",
    defaults: new { controller = "Content", action = "Page", publicationId = UrlParameter.Optional }
);
Sign up to request clarification or add additional context in comments.

1 Comment

publicationId is likely not optional in this case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.