title: passing a variable from cshtml razor to jquery
body: <p>I have a partial view that I am calling on pages as follows :-</p>
  
  <pre><code>@Html.Partial("~/Views/Shared/ImageGallery.cshtml", Model)
  </code></pre>
  
  <p>The code for the actual Jquery of this page is a s follows :-</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      $(document).ready(function () {
  
          $('.modal_block').click(function (e) {
              $('#tn_select').empty();
              $('.modal_part').hide();
          });
  
          $('#modal_link').click(function (e) {
              $('.modal_part').show();
              var context = $('#tn_select').load('/Upload/UploadImage?Page=Article&amp;Action=Edit&amp;id=16', function () {
                  initSelect(context);
              });
              e.preventDefault();
              return false;
          });
  
      });
  &lt;/script&gt;
  </code></pre>
  
  <p>Now this works perfectly, however I need to find a way to pass dynamic vars instead of hard coded vars to this :-</p>
  
  <pre><code>Upload/UploadImage?Page=Article&amp;Action=Edit&amp;id=16
  </code></pre>
  
  <p>In the Model I have all the vars, however I do not know how I can insert them into the Jquery. Any help would be very much appreciated!</p>
  
  <p>---------UPDATE-----------------------</p>
  
  <p>This is the code I am putting into each cshtml that needs the ImageGallery.</p>
  
  <pre><code>&lt;/div&gt;
      @Html.HiddenFor(model =&gt; model.PageViewModel.Page.PageTitle, new { id = "PageTitle"});
      @Html.HiddenFor(model =&gt; model.PageViewModel.Page.PageAction, new { id = "PageAction"});
      @Html.HiddenFor(model =&gt; model.ArticleViewModel.Article.ArticleID, new { id = "ArticleID"});
  &lt;div&gt;
      @Html.Partial("~/Views/Shared/ImageGallery.cshtml", Model)
  &lt;/div&gt;
  </code></pre>
  
  <p>New Javascript in the ImageGallery :-</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  
      var pageTitle = $('#PageTitle').val();
      var pageAction = $('#PageAction').val();
      var id = $('#ArticleID').val();
      $(document).ready(function () {
          $('.modal_block').click(function (e) {
              $('#tn_select').empty();
              $('.modal_part').hide();
          });
          $('#modal_link').click(function (e) {
              $('.modal_part').show();
              var context = $('#tn_select').load('/Upload/UploadImage?Page=' + pageTitle + '&amp;Action=' + pageAction + '&amp;id=' + id, function () {
                  initSelect(context);
              });
              e.preventDefault();
              return false;
          });
      });
  
  &lt;/script&gt;
  </code></pre>
  
  <p>This works fine now</p>