title: Passing the input value from controller to view in MVC
body: <p>I am new to ASP.NET Core MVC. I want to move the text string from controllers to views. Here is my controller.</p>
  <pre><code>public class CalculatorController : Controller
  {
      public string text= &quot;&quot;;
  
      public IActionResult Index()
      {
          ViewData[&quot;Text&quot;] = text;
          return View();
      }
  
      public IActionResult Button1_Click(string button)
      {
          text += button;
          return RedirectToAction(&quot;Index&quot;);
      }
  
      public IActionResult Button2_Click(string button)
      {
          text = text + button;
          return RedirectToAction(&quot;Index&quot;);
      }
  }
  </code></pre>
  <p>In the controller, I make a public string text, in which the button value be stored when <code>button1_Click</code>, it stores its value and shows in the input textbox and when <code>Button2_Click</code> it stores and show both the values of button1 and button2 in the input textbox.</p>
  <p>The input textbox markup is here:</p>
  <pre><code>&lt;input type=&quot;text&quot; asp-controller=&quot;Calculator&quot; asp-action=&quot;Index&quot;  
         value=&quot;@ViewBag.Text&quot; class=&quot;form-control&quot; /&gt;
  </code></pre>
  <p>But this code does not work well.</p>