title: Best way to escape characters before jquery post ASP.NET MVC
body: <p>I am semi-new to ASP.NET MVC. I am building an app that is used internally for my company.</p>
  
  <p>The scenario is this: There are two Html.Listbox's. One has all database information, and the other is initally empty. The user would add items from the database listbox to the empty listbox. </p>
  
  <p>Every time the user adds a command, I call a js function that calls an ActionResult "AddCommand" in my EditController. In the controller, the selected items that are added are saved to another database table.</p>
  
  <p>Here is the code (this gets called every time an item is added):</p>
  
  <blockquote>
    <p>function Add(listbox) {
       ...<br>
       //skipping initializing code for berevity  </p>
    
    <p>var url = "/Edit/AddCommand/" + cmd;</p>
    
    <p>$.post(url);</p>
    
    <p>}</p>
  </blockquote>
  
  <p>So the problem occurs when the 'cmd' is an item that has a '/', ':', '%', '?', etc (some kind of special character)</p>
  
  <p>So what I'm wondering is, what's the best way to escape these characters? Right now I'm checking the database's listbox item's text, and rebuilding the string, then in the Controller, I'm taking that built string and turning it back into its original state.</p>
  
  <p>So for example, if the item they are adding is 'Cats/Dogs', I am posting 'Cats[SLASH]Dogs' to the controller, and in the controller changing it back to 'Cats/Dogs'.</p>
  
  <p>Obviously this is a horrible hack, so I must be missing something. Any help would be greatly appreciated.</p>