0

I have written following code:

@Html.ActionLink("Edit", "EditPost", new { id = item.PostID })

It displays URL like .../Post/EditPost/32 but actually I want to display it like ...../Post/EditPost?ID=32

How is it possible in Razor View???

2 Answers 2

1

The URL construct is generally dictated by the route, if you want to force it to use the query string then just remove any notion of a parameter from it e.g.

routes.MapRoute(
    "EditPostRoute",
    "Post/EditPost",
    new { controller = "Edit", action = "EditPost" }
);

Your @Html.ActionLink code should generate .../Post/EditPost?ID=32.

Sign up to request clarification or add additional context in comments.

Comments

0

Change Action Edit parameter from int to string. Then it will display as you want

public ActionResult Edit(string ID)
{
     =======
     =======
}

@Html.ActionLink("Edit", "EditPost", new { ID = item.PostID },null)

Another solution remove id = UrlParameter.Optional from the Global.asax/Route Table

Comments

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.