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. Commented Apr 8, 2019 at 8:20
  • Yes,you right i want like this `localhost:9210/Index/Product/1 Commented Apr 8, 2019 at 8:21
  • @CodeCaster how can i do this please tell me Commented Apr 8, 2019 at 8:22
  • @icon try the below answer. 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

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

Comments

0

You can specify the route expected with the Route attribute.

[Route("Index/Product/{prodId}")]
public IHttpActionResult UpdateStatus(int prodId)
{
}

1 Comment

Its showing red line blow [Route I have added route line above action result ` [Route("Index/Product/{prodID}")] public ActionResult Product(int prodID)`

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.