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 4083268
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:17:29+00:00 2026-05-20T18:17:29+00:00

I have a simple loginform based on the following modelitem public class LogOnModelItem {

  • 0

I have a simple loginform based on the following modelitem

   public class LogOnModelItem
    {
        [Required(ErrorMessage="Brukernavn er påkrevd")]
        [DisplayName("Brukernavn")]
        public string UserName { get; set; }

        [Required(ErrorMessage="Passord er påkrevd")]
        [DataType(DataType.Password)]
        [DisplayName("Passord")]
        public string Password { get; set; }

        [DisplayName("Husk meg?")]
        public bool RememberMe { get; set; }
    }

The view is :

<h2>Login</h2>

<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()) {
    @Html.ValidationSummary(true)
    <table>
        <tr>
            <td>@Html.LabelFor(model => model.UserName)</td>
            <td>
                @Html.EditorFor(model => model.UserName)
                @Html.ValidationMessageFor(model => model.UserName)
            </td>
        </tr>
        <tr>
            <td>@Html.LabelFor(model => model.Password)</td>
            <td>
                @Html.EditorFor(model => model.Password)
                @Html.ValidationMessageFor(model => model.Password)
            </td>
        </tr>        <tr>
            <td>@Html.LabelFor(model => model.RememberMe)</td>
            <td>
                @Html.EditorFor(model => model.RememberMe)
                @Html.ValidationMessageFor(model => model.RememberMe)
            </td>
        </tr>
     </table>
        <p>
            <input type="submit" value="Create" />
        </p>
}

The controller:

   public ActionResult Login(LogOnModelItem lmi)
    {
        return View(lmi);
    }

When I load this up in the browser the validation is apparently run on pageload. This then outlines the username and password in red, with the error message supplied after each line. I have 3 questions for this, in order of importance:

1: How do I make sure the validation is not run until after the user presses submit.
2: How do I display the validation summary?
3: How do I make the “username” field choosen by default and ready to accept input?

Answer to #1:

public ActionResult Login()
{
    return View();
}
[HttpPost]
public ActionResult Login(LogOnModelItem lmi)
{
    return View(lmi);
}

Answer to #2

@Html.ValidationSummary(false)

Answer to #3

<script type="text/javascript">
    $(document).ready(function () {
        $('#UserName').focus();
    });
</script>
  • 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-05-20T18:17:30+00:00Added an answer on May 20, 2026 at 6:17 pm

    1: How do I make sure the validation is not run until after the user presses submit

    This should already be the case. If you have a GET action rendering this form and supplying a view model there won’t be any validation errors. It’s the POST action that would show the validation messages and if you have client validation enabled it could also happen onblur.

    2: How do I display the validation summary?

    You already did: @Html.ValidationSummary(true)

    3: How do I make the “username” field choosen by default and ready to accept input?

    You could use javascript:

    $(function() {
        $('#UserName').focus();    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple login form, username and password. Basically, When a user is
There are some HTML based games (ie bootleggers.us) that have a simple login form
I have a simple login form that captures username/password with some simple Javascript (JQuery)
i have a simple little form <form id=loginform> <input id=myinput type=text /> <input name=submit
I have simple win service, that executes few tasks periodically. How should I pass
i have simple regular expression: ^123$ Matches are for example 123 1234 etc. How
I have simple issue setting a two-way databinding of a checkbox in Silverlight 3.0.
I have simple form. <form target=_blank action=somescript.php method=Post id=simpleForm> <input type=hidden name=url value=http://...> <input
I have simple SSIS package which reads data from flat file and insert into
I have simple HTML code with some JavaScript. It looks like: <html> <head> <script

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.