title: How to pass a string as a parameter into a javascript function from a View?
body: <p>I've just started to work with ASP.NET MVC projects, I have gotten past the basics, but I came across with a problem recently, I can't pass a string as a id from a View.</p>
  
  <p>So far, I've been passing the id to a javascript function like this:</p>
  
  <pre><code>&lt;script&gt;app.init( &lt;%: ViewContext.RouteData.Values["id"].ToString() %&gt;)&lt;/script&gt;
  </code></pre>
  
  <p>This calls the following javascript function:</p>
  
  <pre><code>var app = {};
  (function (app) {
      var _id;
      app.init = function (id) {
          _id = id;
      }
      app.id = function () {
          return _id;
      }
  })(app);
  </code></pre>
  
  <p>I'm doing this because I need to work with the id to perform operations like submits and ajax calls in javascript (I prefer working with javascript).</p>
  
  <p>So far this has worked with int values, but when I tried to pass a string it fails. For example if I try to access to this url localhost:65097/Device/Edit/D2C02 it shows the following error:</p>
  
  <pre><code>SCRIPT5009: 'D2C02' is undefined
  </code></pre>
  
  <p>When I check the generated html code, the call to the function looked like this:</p>
  
  <pre><code>&lt;script&gt;app.init(D2C02)&lt;/script&gt;
  </code></pre>
  
  <p>Shouldn't the id be passed as 'D2C02' like a string, instead of just D2C02 like a variable? Because that's what I'm understading the browser thinks the id D2C02 represents. How can I make sure the id value is passed on to the javascript function as a string?</p>