Search code examples
c#htmlasp.net-mvcrazorfrontend

Iam trying to use Html.ActionLink to generate url with queryString parameter at the end of it


I am trying to use Html.ActionLink to generate URL with query String parameter at the end of it like:

Controller/Action?id=5

But what i get is:

Controller/Action/5

Using :

@Html.ActionLink((string)ViewBag.Back, "Action", "Controller", new{id = Model.Id }, new { })

How can i pass the id parameter as "?id=" not after "/" Thanks


Solution

  • change action header

    public ActionResult Details(int? detailsId)
    

    and adjust link

    Html.ActionLink((string)ViewBag.Back, "Action", "Controller", new{detailsId = Model.Id }, new { })