Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your input is of type <code>button</code> - these don't do anything without additional client side code.</p> <p>If you want to handle the 'event' on the server in a similar way that you would have in ASP.NET, you should convert it to a submit button. Assuming your controller is called 'Account' and your action is called 'Register' your <strong>current</strong> code would look <em>something</em> like this:</p> <pre><code>public ViewResult Register() { return View(); } </code></pre> <p>You want to start by passing a model to the view:</p> <pre><code>public ViewResult Register() { var registerModel = new RegisterModel(); return View(registerModel); } </code></pre> <p>Your current view is using loosely typed inputs. Since you're passing it a model you can use strongly typed views. Your model should look something like this:</p> <pre><code>public class RegisterMode { public string Firstname { get; set; } public string Surname { get; set; } } </code></pre> <p>To use strongly typed views, change your view to look like this:</p> <pre><code>&lt;%using (Html.BeginForm()) { %&gt; &lt;%=Html.LabelFor(x =&gt; x.Firstname)%&gt; &lt;br/&gt; &lt;%=Html.TextBoxFor(x =&gt; x.Firstname)%&gt; &lt;br/&gt;&lt;br/&gt; &lt;%=Html.LabelFor(x =&gt; x.Surname)%&gt; &lt;br/&gt; &lt;%=Html.TextBoxFor(x =&gt; x.Surname)%&gt; &lt;br/&gt;&lt;br/&gt; &lt;input type="submit" value="Register"/&gt; &lt;%} %&gt; </code></pre> <p>What we've done is told the view to build labels and text boxes for your RegisterModel type. This will allow the model values to be automatically mapped when you POST the form to the controller. </p> <p>Do accept the post, we need to add a new Action to the controller, with the same name, but accepting a parameter of type RegisterModel:</p> <pre><code>public ActionResult Register(RegisterModel model) { // do something with the model, such as inserting it into the database. // model.Firstname will contain the value of the firstname textbox // model.Surname will contain the value of the surnaem textbox return RedirectToAction("Success"); } </code></pre> <p>One last thing to do, to be safe, is to add the <code>[HttpGet]</code> and <code>[HttpPost]</code> attributes to your controller actions to control the methods they accept:</p> <pre><code>[HttpGet] public ViewResult Register() </code></pre> <p>and</p> <pre><code>[HttpPost] public ActionResult Register(RegisterModel model) </code></pre> <p>I suggest you read up on MVC at <a href="http://www.asp.net/mvc" rel="noreferrer">http://www.asp.net/mvc</a> and read the NerdDinner tutorial chapter in Professional MVC (available for free online in PDF format).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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