title: How to passing Action value to PartiellView in Asp.Net Mvc project
body: <p>In my Products PartiallView table</p>
  
  <pre><code>@model IEnumerable&lt;Products.Models.Product&gt;
  </code></pre>
  
  <p>I'am trying (hide) not showing some buttons if user departmentId is not the same as product departmentId</p>
  
  <pre><code>&lt;table class="table table-responsive table-hover table-striped"&gt;
      &lt;tr&gt;
          &lt;th&gt; Product type
  
          &lt;/th&gt;
  
          &lt;th&gt;&lt;/th&gt;
  
      &lt;/tr&gt;
  
      @foreach (var item in Model)
      {
          &lt;tr&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.ProductName)
              &lt;/td&gt;
  
              //  I want to hide if current inlogged userDepartmentId is not the same as product departmentId
              // Like @if(@item.ProductDeptId == userDepartmentId) {
              &lt;td&gt;
                  &lt;Button class="btn btn-success glyphicon btn-xs glyphicon-plus" onclick="return EditDelete(@(item.ProductId) )"&gt;Edit/Delete&lt;/Button&gt;&amp;nbsp;
  
              &lt;/td&gt;
              }
          &lt;/tr&gt;
      }
  </code></pre>
  
  <p>I tried to write this code in the begining of my partiellView but it is kind of </p>
  
  <p>complicated and geting errors</p>
  
  <pre><code> @model IEnumerable&lt;Products.Models.Product&gt;
      @using Microsoft.AspNet.Identity
      @using Products.Models;
  
      @{
  
              string user = User.Identity.Name;
           private ApplicationDbContext context = new ApplicationDbContext();
          int UserDeptId = context.Users.Where(u =&gt; u.UserName == user).Select(d =&gt; d.DeptId).SingleOrDefault();
      }
  </code></pre>
  
  <p>Now  I created Action method in my Home controller</p>
  
  <pre><code>public ActionResult GetDeptId()
          {
              string user = User.Identity.Name;
  
              return View(context.Users.Where(u =&gt; u.UserName == user).Select(d =&gt; d.DeptId).SingleOrDefault());
  
          }
  </code></pre>
  
  <p>So my question is: How can  I pass value of this action in my PartiellView and save it in a variable and use it this variable in my If condition ? Thank you.</p>
  
  <p>// Trying to do as Stephen Vakil idea </p>
  
  <pre><code>public class Product
      {
          public int ProductId { get; set; }
          public string productName { get; set; }
          public int DepartmentId { get; set; }
  
  
      }
  
  public class ProductModelView
      {
          public int ProductId { get; set; }
          public string productName { get; set; }
          public int DepartmentId { get; set; }
          public int UserDepartmentId { get; set; }
  
      }
  
   [HttpGet]
          public ActionResult Lager()
          {
              using (context)
              {
                  string user = User.Identity.Name;
  
                  int DeptId = Convert.ToInt32(context.Users.Where(u =&gt; u.UserName == user).Select(d =&gt; d.DepartmentId).SingleOrDefault());
  
  
                  // Here I don't know how to continue ... I try like this
                  Product pr = new Product();
                  ProductModelView prModel = new ProductModelView();
                  prModel.ProductId = pr.ProductId;
                  prModel.productName  = pr.productName ;
          prModel.DepartmentId= pr.DepartmentId;
          prModel.UserDepartmentId = DeptId;
                   // And then .. How to return and what to return ????
  
                  return (PartialView("_ProductList",  prModel)); ?? Is this right? Returning prModel ???
  
              }
  </code></pre>