title: How to pass variable from controller to view
body: <p>I have tried to pass a value from my controller to a view but it has not worked.</p>
  
  <p>I am passing the value from a view to a controller using an Ajax script which works perfectly fine. Then what I want to do is to pass that value to the Index controller and show it in the View for the Index.</p>
  
  <p>Here is my Controller :</p>
  
  <pre><code>    static string global;
      public ActionResult Index(string id)
      {
          TempData["var"] = id;
          return View();
      }
      [HttpPost]
      public object functon(string data)
      {
          return Index(data);
      }
  </code></pre>
  
  <p>here is my View :</p>
  
  <pre><code>@{
      ViewBag.Title = "Index";
  }
  
  &lt;h2&gt;Index&lt;/h2&gt;
  
  &lt;input class="form-group" id="input"/&gt;
  &lt;button class="btn btn-success" id="send"&gt;Send&lt;/button&gt;
  
  @if ((string)TempData["var"] == null)
  {
      &lt;span&gt;Check&lt;/span&gt;
  }
  else
  {
      &lt;h1&gt;@TempData["var"].ToString()&lt;/h1&gt;
  }
  
  @* SCRIPT *@
  &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
          $(function () {
              $("#send").click(function () {
                  $.ajax({
                      type: "POST",
                      url: "/Acceptvalue/functon",
                      data: '{data: "' + $("#input").val() + '" }',
                      contentType: "application/json; charset=utf-8",
                      dataType: "json",
                      success: function (response) {
                      },
                      failure: function (response) {
                      },
                      error: function (response) {
                      }
                  });
              });
          });
  &lt;/script&gt;
  </code></pre>