title: Dynamic "Favorite" button - ASP.NET MVC
body: <p>I have created a table which dynamically generates records using the "Infinite Loading" process, I have a button in my HTML Code which i need to use to allow users to add the item in their favourite - so this is my HTML code</p>
  
  <pre><code>@model List&lt;PagesAuth.Models.Links.MLink&gt;
  
  @foreach (var I in Model)
  {
      &lt;tr&gt; 
          &lt;td class="v-align-top" id="itemcard"&gt;                
              &lt;h4 class="card-title"&gt;
                  @I._title 
                  &lt;small&gt;&lt;cite&gt;@I._tp_created.ToString("dd MMM yyyy")&lt;/cite&gt; /small&gt;
              &lt;/h4&gt;            
              &lt;div class="pull-right" id="options"&gt;
                  &lt;ul class="list-inline text-right" &gt;                   
                      @if (I._tp_favourite == 0)
                      {
                      &lt;li&gt;&lt;button class="btn-link glyphicon glyphicon-heart-empty" onclick="location.href='@Url.RequestContext .Action("_Fav", "Home", "@I._id")'"&gt;&lt;/button&gt;&lt;/li&gt;
                      }
                      else
                      {
                    &lt;li&gt;&lt;button class="btn-link glyphicon glyphicon-heart-empty" onclick="location.href='@Url.RequestContext .Action("_UnFav", "Home", "@I._id")'"&gt;&lt;/button&gt;&lt;/li&gt;
                      }
                  &lt;/ul&gt;
              &lt;/div&gt;    
          &lt;/div&gt;
  
          &lt;/td&gt;
      &lt;/tr&gt;
  }
  </code></pre>
  
  <p>I am trying to use "Favourite" button to allow user to add that website to their favourite list (I am ok with the DB updates etc) </p>
  
  <pre><code>&lt;ul class="list-inline text-right" &gt;                   
                      @if (I._tp_favourite == 0)
                      {
                      &lt;li&gt;&lt;button class="btn-link glyphicon glyphicon-heart-empty" onclick="location.href='@Url.RequestContext .Action("_Fav", "Home", "@I._id")'"&gt;&lt;/button&gt;&lt;/li&gt;
                      }
                      else
                      {
                    &lt;li&gt;&lt;button class="btn-link glyphicon glyphicon-heart-empty" onclick="location.href='@Url.RequestContext .Action("_UnFav", "Home", "@I._id")'"&gt;&lt;/button&gt;&lt;/li&gt;
                      }
                  &lt;/ul&gt;
  </code></pre>
  
  <ul>
  <li><p>What I want to know is how to achieve this on user front-end - Like I thought I should just create a PartialView and make it child action only in my controller, send it ID and do DB Processing  </p>
  
  <pre><code>[ChildActionOnly]
  
  public ActionResult _Fav(int ID)
  
  {//Do DB Processing    
  
  
      return PartialView(ID);
  
  }
  </code></pre></li>
  </ul>
  
  <p>First of all the following does not work</p>
  
  <pre><code>onclick="location.href='@Url.RequestContext .Action("_UnFav", "Home", "@I._id")'"
  </code></pre>
  
  <p>Second, if I end up making this work, it will still refresh the page and I don't want that. </p>
  
  <p>Is there a better way to achieve this</p>
  
  <p>Cheers</p>