Unable to display MVC 5 validation error messages on view
<p>I have a specific problem using MVC 5 validation to display error messages if the user hasn't properly entered everything on the page. The HTML markup of the form is as following: </p>

<pre><code>                @using (Html.BeginForm("RegisterDo", "User", FormMethod.Post))
                {
                    &lt;div&gt;
                        @Html.ValidationMessageFor(model =&gt; model.FirstName)
                        @Html.TextBoxFor(m =&gt; m.FirstName, new { placeholder = "First name", @class = "form-control", @type = "text" })



                    &lt;/div&gt;
                    &lt;div&gt;
                        @Html.ValidationMessageFor(model =&gt; model.LastName)
                        @Html.TextBoxFor(m =&gt; m.LastName, new { placeholder = "Last name", @class = "form-control", @type = "text" })


                    &lt;/div&gt;
                    &lt;div&gt;
                        @Html.ValidationMessageFor(model =&gt; model.Email)
                        @Html.TextBoxFor(m =&gt; m.Email, new { placeholder = "Email", @class = "form-control", @type = "email" })

                    &lt;/div&gt;
                    &lt;div&gt;
                        @Html.ValidationMessageFor(model =&gt; model.Password)
                        @Html.TextBoxFor(m =&gt; m.Password, new { placeholder = "Password", @class = "form-control", @type = "password" })

                    &lt;/div&gt;
                    &lt;div&gt;
                        @Html.ValidationMessageFor(model =&gt; model.PasswordConfirm)
                        @Html.TextBoxFor(m =&gt; m.PasswordConfirm, new { placeholder = "Confirm password", @class = "form-control", @type = "password" })


                    &lt;/div&gt;
                    &lt;div&gt;
                        @Html.ValidationMessageFor(model =&gt; model.SelectedCountryId)
                        @Html.DropDownListFor(model =&gt; model.SelectedCountryId, Model.Countries, "-- Please select a country --", new { @class = "select2_single form-control select2-hidden-accessible", @tabindex = "-1" })

                    &lt;/div&gt;
                    &lt;div&gt;
                        &lt;input class="btn btn-default submit" type="submit" value="Register" /&gt;
                    &lt;/div&gt;
                }
</code></pre>

<p>Please note that I have a dropdown list that I need to fill initially when the view is rendered (i.e. I have to pass the countries list onto the view in order to render it properly). The issue that I have here is that when I click the "register" button, the code from my action isn't triggered AT ALL. Instead I simply get the URL in my browser as following:</p>

<pre><code>http://localhost:60617/user/register?FirstName=&amp;LastName=&amp;Email=&amp;Password=&amp;PasswordConfirm=&amp;SelectedCountryId=
</code></pre>

<p>And the error messages are not displayed at all... The code isn't triggered at all...</p>

<p>These are my two actions:</p>

<pre><code>  [HttpPost]
        [ActionName("Register")]

        public ActionResult DoRegister(UserRegistrationViewModel model)

        {
            if (ModelState.IsValid)
            {
                var user = new Users();
                user.FirstName = model.FirstName;
                user.LastName = model.LastName;
                user.Email = model.Email;
                user.PasswordSalt = Helpers.PasswordHelper.CreateSalt(40);
                user.PasswordHash = Helpers.PasswordHelper.CreatePasswordHash(model.Password, user.PasswordSalt);
                user.CountryId = Convert.ToInt32(model.SelectedCountryId);
                user.Active = true;
                Connection.ctx.Users.Add(user);
                Connection.ctx.SaveChanges();
                var role = new UserRoles();
                role.RoleId = 2;
                role.UserId = user.UserId;
                role.Active = true;
                user.UserRoles.Add(role);
                Connection.ctx.SaveChanges();
                return RedirectToAction("Success");
            }
            else
            {
                return View("Register", model);
            }
        }
        public ActionResult Register()
        {
            var model = new UserRegistrationViewModel();
            var countries = Connection.ctx.Countries.OrderBy(x =&gt; x.CountryName).ToList();
            model.Countries = new SelectList(countries, "CountryId", "CountryName");
            return View(model);
        }
</code></pre>

<p>First action is responsible for rendering the view, and second one is responsible for logic when the user registers...</p>

<p>What am I doing wrong here. I'm missing out something very obvious here, but I just cant see it... :(</p>

<p>Edit here is the ViewModel:</p>

<pre><code>  public class UserRegistrationViewModel
    {
        [Required(ErrorMessage = "First name is required!")]
        public string FirstName { get; set; }

        [Required(ErrorMessage = "Last name is required!")]
        public string LastName { get; set; }

        [Required(ErrorMessage = "Email name is required!")]
        public string Email { get; set; }

        [Required(ErrorMessage = "Password name is required!")]
        public string Password { get; set; }

        [Required(ErrorMessage = "Password confirmation name is required!")]
        public string PasswordConfirm { get; set; }
        [Required(ErrorMessage = "Country needs to be selected!")]
        public int SelectedCountryId { get; set; }


        public SelectList Countries { get; set; }
}
</code></pre>