0

I am trying to hide or replace string in the URL after mapping to controller from view.

View

    <a href='@Url.Action("Product", "Index", new { prodID [email protected] 
    })'>

Controller

      public ActionResult Product()
      {

        return View(model);
      }

Now I am getting this in URL like this http://localhost:9210/Index/Product?prodID=1 But I want url like this http://localhost:9210/Index/Product/1 So how can I do this? Please help

4
  • Then you have to have a route defined /Product/{prodID}, either in your route config or through attributes.
    – CodeCaster
    Commented Apr 8, 2019 at 8:20
  • Yes,you right i want like this `localhost:9210/Index/Product/1
    – don
    Commented Apr 8, 2019 at 8:21
  • @CodeCaster how can i do this please tell me
    – don
    Commented Apr 8, 2019 at 8:22
  • @icon try the below answer.
    – Gagan Deep
    Commented Apr 8, 2019 at 8:29

2 Answers 2

1

You have to pass like this.

<a href='@Url.Action("Product", "Index", new { id [email protected] 
})'>

Probably becuase the parameter defined in the route.config file will be by the name id and not prodID

0
0

You can specify the route expected with the Route attribute.

[Route("Index/Product/{prodId}")]
public IHttpActionResult UpdateStatus(int prodId)
{
}
1
  • Its showing red line blow [Route I have added route line above action result ` [Route("Index/Product/{prodID}")] public ActionResult Product(int prodID)`
    – don
    Commented Apr 8, 2019 at 8:46

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.