title: In a single razor view, how can i retrieve values passed from different methods of a controller?
body: <p>I'm working on a basic application.</p>
  
  <p>This is the main controller:</p>
  
  <pre><code>   public ActionResult Index()
      {
          var all = _context.mainz.ToList();
          var vm = new mainViewModel()
          {
              main_lst = all
          };
  
          return View(vm);
      }
  
      public ActionResult Details()
      {
          var dtl = _context.mainz.ToList();
          var vm = new mainViewModel()
          {
              main_lst = dtl
          };
          return View(vm);
      }
  
  
         public ActionResult count()
      {
          var ct = (from i in _context.mainz
                    where i.event_title != null
                    select i).ToList();
          var vm = new countVm()
          {
            count = ct
          };
          return View(vm);
      }
  </code></pre>
  
  <p>In this controller Index and Details Methods are connected to two different razor views as follows:</p>
  
  <p>This is the razor view for Index</p>
  
  <pre><code>@model testtt.ViewModel.mainViewModel
  
  @{
  ViewBag.Title = "Index";
  Layout = "~/Views/Shared/_Layout.cshtml";
  }
  
  
  
  &lt;ul&gt;
  @foreach (var item in Model.main_lst)
  {
      &lt;li&gt;@item.event_title&lt;/li&gt;
  }
  
  &lt;/ul&gt;
  </code></pre>
  
  <p>This is the razor view for Details</p>
  
  <pre><code>@model testtt.ViewModel.mainViewModel
  @{
  ViewBag.Title = "Details";
  Layout = "~/Views/Shared/_Layout.cshtml";
   }
  
  &lt;ul&gt;
  @foreach (var item in Model.main_lst)
  {
     &lt;li&gt;@item.event_description&lt;/li&gt;
  }
  &lt;/ul&gt;
  </code></pre>
  
  <p>This is the mainViewModel</p>
  
  <pre><code>namespace testtt.ViewModel
  {
  public class mainViewModel
  {
      public List&lt;main&gt; main_lst { get; set; }
      public mainViewModel()
      {
          main_lst = new List&lt;main&gt;();
      }
  }
  }
  </code></pre>
  
  <p>Now in the main controller above, if you have noticed i have a third method as count which is connected to a partial view as follows:</p>
  
  <pre><code>@model testtt.ViewModel.countVm
  &lt;p&gt;count is @Model.count.Count()&lt;/p&gt;
  </code></pre>
  
  <p>And the countVm or (count view model) is as follows:</p>
  
  <pre><code>namespace testtt.ViewModel
  {
  public class countVm
  {
      public List&lt;main&gt; count { get; set; }
      public countVm()
      {
          count = new List&lt;main&gt;();
      }
  }
  }
  </code></pre>
  
  <p>Everything is working fine till this moment, 
  Now as per application requirement i have to add this count partial view to all other razor views as follows:</p>
  
  <pre><code> @Html.Partial("count")
  </code></pre>
  
  <p>But when i add it into Index or Details razor views it generates an error as:</p>
  
  <pre><code>The model item passed into the dictionary is of type 'testtt.ViewModel.mainViewModel', but this dictionary requires a model item of type 'testtt.ViewModel.countVm'.
  </code></pre>
  
  <p>Now lets say this count method has some identical data that has to be passed to all other razor views but not separately, because separately passing will be time consuming and suppose tomorrow due to any reason if the logic is updated then i have to go to each and every single method individually and have to update them accordingly, which is not possible if we are assuming more than 100 methods.</p>
  
  <p>So in short, i am looking for a way to retrieve data from two view models in a single razor view?</p>