0

I am trying to understand asp.net server implementation and routing in particular. I have tried to search this forum for answers(for instance this link; WebApi 2.0 Routes not matching with query parameters?, but I havent gotten anything to work. I would like to have a form on the client side:

<"form id="search-form" name="search-form" method="get" action="page.html" 
      onsubmit="return validate();">
      <"input id="inputText" name="question" type="text" 
              placeholder="Search..." class="inputsearch">
<"/form>

This will allow me to send a query (for instance "test") to the server, which would look like "page.html?question=test". My controller is called products (but it seems to me that I do not need to specify it in an action tag on the form, so I was thinking that I need some routing like:

[HttpGet]

    [Route("~/api/products?{queryWord}")]
      public IHttpActionResult test(string queryWord)
    {
        Debug.Write(queryWord);
        return Ok("<html>hey</html>");
    }

That seemed to be valid from the answers in that link, but I get an error message:

The route template cannot start with a '/' or '~' character and it cannot contain a '?' character. Parameter name: routeTemplate

Community
  • 1
  • 1
stian
  • 1,947
  • 5
  • 25
  • 47
  • You seem to be mixing up WebForms, ASP.NET MVC, and WebApi. You mention that you have a controller, so I assume you are really using ASP.NET MVC. I would recommend you find a tutorial on ASP.NET MVC because it would definitely cover what you're trying to do, plus it would provide you with a basis for future work. You can start here: [Getting Started with ASP.NET MVC](http://www.asp.net/mvc/tutorials/mvc-5/introduction/getting-started) – Brad Rem Mar 01 '14 at 19:56
  • i am using an ordinary asp .net web application and clicked also on web api (i believe it was called (do not have visual studios on my computer)) – stian Mar 02 '14 at 00:43
  • and i have been reading/following the getting started with web api 2 (C#) – stian Mar 02 '14 at 00:50
  • @bradRem. Do you find any tutorials using a form and describing querystrings (?) Routing? – stian Mar 02 '14 at 14:54

0 Answers0