Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>in the aspx:</p> <pre><code> &lt;%Html.BeginForm("Hello","Home",FormMethod.Post);%&gt; &lt;!--Name of method, name of controller, formmethod --&gt; &lt;input type="text" id="userName" maxlength="50" name="userName"/&gt; &lt;input id="Submit1" type="submit" value="Say Hello!" /&gt; &lt;%Html.EndForm();%&gt; &lt;h2&gt;&lt;%= Html.Encode(TempData["Message"]) %&gt;&lt;/h2&gt; </code></pre> <p>In the Controller (HomeController in this example):</p> <pre><code>public ViewResult Hello(string userName) //note this variable is exactly what is the name of text input on page { //simple example, take input and pass back out TempData["Message"] = "Hello, " + userName; return View("Index",TempData); } </code></pre> <p><strong><em>EDIT: To address additional question about maintaining URL</em></strong></p> <p>One method to accomplish "staying in place" as far as your URL is to "overload" the Index method of your controller like below</p> <pre><code>[AcceptVerbs(HttpVerbs.Post)] //This is KEY &lt;----- public ActionResult Index(string userName) { //simple example, take input and pass back out TempData["Message"] = "Hello, " + userName; return View("Index",TempData); } </code></pre> <p>Then in your Index.aspx change the Html.Begin Form like below, your just pointing to the default action now</p> <pre><code>&lt;%Html.BeginForm("Index","Home",FormMethod.Post);%&gt; </code></pre> <p>Since you are posting to the controller and not getting(the default index action) the version that is setup to AcceptVerb POST and take the userName string will run and your URL should be maintained</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload