locked
How Do I Remove A Question Mark From My Url RRS feed

  • Question

  • User1349647816 posted

    Hi,

    I am currently using asp.net mvc attribute routing on my controller but it returns a question mark in the url, here's my code

    [Route("ViewAd/{Desc}", Name = "mv")]        
    public ActionResult ViewSingleAd(string Desc){}

    The url it returns is for example "http://mysite.com/View/mv?Desc=Renault-Sandero-900T-Dynamique", how do I get rid of the ? in the url?

    Saturday, April 6, 2019 10:36 AM

All replies

  • User1120430333 posted

    ShatterStar

    Hi,

    I am currently using asp.net mvc attribute routing on my controller but it returns a question mark in the url, here's my code

    [Route("ViewAd/{Desc}", Name = "mv")]        
    public ActionResult ViewSingleAd(string Desc){}

    The url it returns is for example "http://mysite.com/View/mv?Desc=Renault-Sandero-900T-Dynamique", how do I get rid of the ? in the url?

    The "?" specifies that a variable/parameter "Desc" and its value/data is being passed into the ActionMethod via the URL. The ActionMethod's signature specifies that Desc is to be passed into it.

    It's how things work. 

    https://help.surveygizmo.com/help/url-variables

    Is it not suppose to be the below, since you are doing attribute routing? Otherwise, I think you will get a 404 not found as it cannot find the Web ActionMethod based on the URL you have been using. I use ActionName routing myself in WebAPI(s). I have not used routing in MVC.

     "http://mysite.com/ViewAd/mv?Desc=Renault-Sandero-900T-Dynamique"

    Saturday, April 6, 2019 11:20 AM
  • User475983607 posted

    Hi,

    I am currently using asp.net mvc attribute routing on my controller but it returns a question mark in the url, here's my code

    [Route("ViewAd/{Desc}", Name = "mv")]        
    public ActionResult ViewSingleAd(string Desc){}

    The url it returns is for example "http://mysite.com/View/mv?Desc=Renault-Sandero-900T-Dynamique", how do I get rid of the ? in the url?

    Unclear.  How are you building the URL?  Have you enabled attribute routing?  Is this an MVC 5 application?  MVC Core?

    Saturday, April 6, 2019 12:48 PM