title: Using jQuery to change onclick attribute
body: <p>In MVC 5, I have a controller <code>Image</code>, with an action <code>Info</code>, which takes a string parameter <code>id</code>. In a view, I have a button <code>info</code>, and I want to change its <code>onclick</code> attribute using jQuery. Within the jQuery, there is a string variable called <code>file</code>, which I want to pass as the parameter.</p>
  
  <p>I have tried the following two solutions, but neither work.</p>
  
  <p><strong>Solution 1:</strong></p>
  
  <pre><code>$("#info").attr('onclick', "location.href='@Url.Action("Info", "Image")?id='" + file);
  </code></pre>
  
  <p>This sets the <code>onclick</code> attribute to be equal to:</p>
  
  <pre><code>location.href='/Image/Info?id='1234
  </code></pre>
  
  <p>(here, <code>1234</code> is the value of <code>file</code>).</p>
  
  <p><strong>Solution 2:</strong></p>
  
  <pre><code>$("#info").attr('onclick', "location.href='@Url.Action("Info", "Image")?id=' + file + ");
  </code></pre>
  
  <p>This sets the <code>onclick</code> attribute to be equal to:</p>
  
  <pre><code>location.href='/Image/Info?id=' + file +
  </code></pre>
  
  <p>Neither of these work when the button is pressed. What's the solution?</p>