title: Injecting a string into a javascript on an asp.net mvc view
body: <p>I have a view that contains a javascript function that i need to init/call when the page loads. The method is static but it needs to be called with some parameteres (a list of Id's) - this list is dynamic and varies by some querystring parameters (i can not generate the list clientside from the querystring).</p>
  
  <p>So i need to generate this list server-side.</p>
  
  <p>My options are, as far as i see it:</p>
  
  <blockquote>
    <p>1) Make an ajax call on the client, requesting the ids from the server.</p>
    
    <p>2) Inject/inserting the ids directly on the view (it is a property on the viewmodel).</p>
  </blockquote>
  
  <p>No matter how i turn it, option 2 seems the most sane. I already got the data ready on the viewmodel and thus it's ready when the view is populated - i see no reason to make an extra request to the server, just to get the data.</p>
  
  <p>I know many would think it's a bad idea to inject something dynamic into an otherwise static javascript. For that i could simply just inject a new javascript, holding only the Ids and a call to the static javascript method, which is what i really want to do.</p>
  
  <p>My problem is this though: When i write my asp.net &lt;%= %> includes, VS IDE stops highligting, making me think i might be on the wrong track? Surely i'm not the only one needing to output something in a javascript block in asp.net mvc?</p>