Configure the parameter name in the controller action to display the HTTP request parameter

I am having a problem in that I have to map a fixed URL parameter containing an underscore (like buy_id) for the controller.

    public ActionResult Index(
        long purchase_Id, 

This works, and that is not my problem. What annoys me is the underscore in the parameter name, because I cannot change this URL parameter. It was called buy_id

eg. http://www.example.com/Order?purchase_id=12123

Is there any chance of getting the following that works without changing the URL parameter?

    public ActionResult Index(
        long purchaseId, 

Thank you for your help.

+3
source share
1 answer
public ActionResult Index()
{
    string purchaseId = Request["purchase_id"];
    return View();
}

or

public ActionResult Index([Bind(Prefix="purchase_id")]string purchaseId)
{
    return View();
}
+5
source

Source: https://habr.com/ru/post/1761671/


All Articles