title: Pass C# Model from View to Javascript
body: <p>I'm passing this ViewModel to my View:</p>
  
  <pre><code>  public class DashboardViewModel
    {
      public List&lt;UserTask&gt; UserTasks {get; set;}
  
      public List&lt;WorkItem&gt; WorkItems {get; set;}
    }    
  </code></pre>
  
  <p>and from within the View I'm iterating through the WorkItems like this:</p>
  
  <pre><code> @foreach (var item in Model.WorkItems)
   {
      @item.Name
      @item.HoursLogged
      &lt;button value="@item"&gt;UPDATE&lt;/button&gt;
   }
  </code></pre>
  
  <p>When I click on the button a jQuery function is opening up a modal.</p>
  
  <p>I need to pass to the modal the item in order to display all the item infos.</p>
  
  <p>This is the javascript function:</p>
  
  <pre><code>$(buttonEl).click(function () {
     //code to open modal
     var item = this.value;
  });
  </code></pre>
  
  <p>The value passed in "this.value" is not an object but a string with the namespace of the WorkItem.</p>
  
  <p>I have also tried with inline onclick function:</p>
  
  <pre><code>&lt;button onclick="openModal('@item')"&gt;UPDATE&lt;/button&gt;
  </code></pre>
  
  <p>but with the same result.</p>
  
  <p>Any idea?</p>