Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8369083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:33:23+00:00 2026-06-09T13:33:23+00:00

In my MVC3 app on invalidate form, focus is not set on the first

  • 0

In my MVC3 app on invalidate form, focus is not set on the first select list (if the select list data is empty/invalid). Select list is invalidated but focus is not set. In case of input type i.e textbox, radio etc it works fine. I wonder what’s missing??

Cool...here comes the model and view...
**Model**

 public class RegisterModel
    {
        [Remote("CheckDuplicateUserName","Account")]
        [Display(Name = "User name")]
        [Required(ErrorMessage = "This field is required.")]
        [StringLength(30)]
        public string UserName { get; set; }


        [DataType(DataType.EmailAddress)]
        [Display(Name = "Email address")]
        [Remote("CheckDuplicateEmail", "Account")]
        [Required(ErrorMessage = "This field is required.")]
        public string Email { get; set; }


        [ValidatePasswordLength]
        [DataType(DataType.Password)]
        [Display(Name = "Password")]
        [Required(ErrorMessage = "This field is required.")]
        [StringLength(30)]
        public string Password { get; set; }

        [DataType(DataType.Password)]
        [Display(Name = "Confirm password")]
        [Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
        [StringLength(30)]
        public string ConfirmPassword { get; set; }


        //additional fields

        [Display(Name = "Name")]
        [Required(ErrorMessage = "This field is required.")]
        [StringLength(30)]
        public string Name { get; set; }

        [Display(Name = "Address")]
        [StringLength(100)]
        public string Address { get; set; }

        [Display(Name = "City")]
        [Required(ErrorMessage = "This field is required.")]
        public string City { get; set; }


    }

**View** 


@model MyShowCase.Models.RegisterModel
@{
    ViewBag.Title = "Register";
}

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

@using (Html.BeginForm("Register","Account"))
{
    @Html.ValidationSummary(true, "Account creation was unsuccessful. Please correct the errors and try again.")
    <div id="register">
       <div class="editor-label">
                @Html.LabelFor(m => m.UserName)
            </div>
            <div class="editor-field">
                @Html.TextBoxFor(m => m.UserName) *
                @Html.ValidationMessageFor(m => m.UserName)
                  <span class="instruction"> username should be alphanumeric without any special characters.</span>

            </div>
            <div class="editor-label">
                @Html.LabelFor(m => m.Password)
            </div>
            <div class="editor-field">
                @Html.PasswordFor(m => m.Password) *   @Html.ValidationMessageFor(m => m.Password)
                <span class="instruction"> Passwords are required to be a minimum of @ViewBag.PasswordLength characters in length.</span>


            </div>
            <div class="editor-label">
                @Html.LabelFor(m => m.ConfirmPassword)
            </div>
            <div class="editor-field">
                @Html.PasswordFor(m => m.ConfirmPassword) *
                @Html.ValidationMessageFor(m => m.ConfirmPassword)
            </div>
            <div class="editor-label">
                @Html.LabelFor(m => m.Name)
            </div>
            <div class="editor-field">
                @Html.TextBoxFor(m => m.Name) *
                @Html.ValidationMessageFor(m => m.Name)
                  <span class="instruction"> Specify your Full Name here.</span>

            </div>

     <div class="editor-label">
                @Html.LabelFor(m => m.City)
            </div>
            <div class="editor-field">
                <select id="City" name="City">
                    <option value="" selected="selected"></option>
                    <option >Dubai</option>
                    <option >Abu Dhabi</option>

                </select>
                *
                @Html.ValidationMessageFor(m => m.City)
            </div>

    </div>
}

Here is all what i have, the problem is that focus is not set on "City" Dropdown if City is not selected. Its validated but the focus in not set....


web.config 
  <appSettings>
        <add key="ClientValidationEnabled" value="true" />
        <add key="UnobtrusiveJavaScriptEnabled" value="true" />

    </appSettings>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T13:33:24+00:00Added an answer on June 9, 2026 at 1:33 pm

    The class required was missing. Set style of the select list as class=’required’ and it works fine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an asp.net MVC3 app with various bits of form data and a
I have MVC3 app with form for edit data. This for include only dropdownlist.
For some reason emlah is not logging missing images in my MVC3 app. Everything
I am building my first mvc3 app. A few questions I have are: 1)
When creating a new asp.net mvc3 app you get the logon and register form
I have an ASP.NET MVC3 app that features a form with a nested-table input
In the usual AccountController in my MVC3 app, if returnUrl is set (in my
The server is hosting Asp.net mvc3 app and the Browser culture is set to
I'm building a simple mvc3 app using jqgrid. My form currently calls a function
This is an MVC3 app. I have read and read and read but i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.