title: How to send data to _layout.cshtml from controller?
body: <p>I need to send ID of the user to <code>_layout.cshtml</code> but I couldn't make it through <code>viewbag</code> or model. How can I do it?</p>
  
  <p>Do I need to send it specifically to the <code>_layout</code>? Here is my Action Method: </p>
  
  <pre><code>public ActionResult validate()
  {
      List&lt;user&gt; list = cx.users.ToList&lt;user&gt;();
      user u = new user();
      u.username = Request.Form["username"];
      u.password = Request.Form["password"];
      for (int i = 0; i &lt; list.Count; i++)
      {
          if (list[i].username == u.username &amp;&amp; list[i].password == u.password)
          {
              ViewBag.x = list[i].Id;
              return RedirectToAction("index", "Home",  list[i]);
          }
      }
      return RedirectToAction("login");
  }
  </code></pre>