title: How to pass values from controller to view in asp.net?
body: <p>I am developing an application where I need to pass the value of username from a controller to a view.
  i tried ViewData as given in <a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.viewdatadictionary.aspx" rel="noreferrer">http://msdn.microsoft.com/en-us/library/system.web.mvc.viewdatadictionary.aspx</a></p>
  
  <p>My code in controller is </p>
  
  <pre><code>public ActionResult Index(string UserName, string Password)
  {
          ViewData["UserName"] = UserName;
          return View();
  }
  </code></pre>
  
  <p>where username and password are obtained from another form.</p>
  
  <p>And the code in the view is</p>
  
  <pre><code>@{
      ViewBag.Title = "Index";  
  }
  &lt;h2&gt;Index&lt;/h2&gt;
  &lt;%= ViewData["UserName"] %&gt;
  </code></pre>
  
  <p>But when I run this code, the display shows &lt;%= ViewData["UserName"] %> instead of the actual username say, for example "XYZ".</p>
  
  <p>How should I display the actual UserName?</p>
  
  <p>Thank you very much in advance for your help.</p>