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

  • Home
  • SEARCH
  • 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 8132769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:25:22+00:00 2026-06-06T09:25:22+00:00

This is my model of my asp.net mvc 2 project : using System; using

  • 0

This is my model of my asp.net mvc 2 project :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Web.DynamicData;
using System.Web.Security;
using System.Globalization;
using System.Web.Profile;

namespace EMS.Models
{
public class UserModels
{

    [Required(ErrorMessage = "*")]
    public string userName { get; set; }

    [Required(ErrorMessage = "*")]
    public string passWord { get; set; }
  }
}

And this is my view :

 <% Html.EnableClientValidation(); %>
    <% using (Html.BeginForm()) { %>

    <table>
            <tr>
                <td><label for="userlogin">User Login:</label></td>
                <td>
                    <%: Html.TextBoxFor(m => m.userName, new { id = "userName"})%> 
                    <%: Html.ValidationMessageFor(m => m.name)%>
                </td>
                <td><label for="password">Password:</label></td>
                <td>
                    <%: Html.PasswordFor(m => m.passWord, new { id = "password"})%> 
                    <%: Html.ValidationMessageFor(m => m.passWord)%>
                </td>
             </tr>
            <tr>
                <td colspan="4">
                    &nbsp; <input type="submit"  name="enter_infor" id="enter_infor" value="Enter Information"/>
                </td>
            </tr>
    </table>

And this is my controller :

    [HttpPost]
    public ActionResult UserMaintenance(FormCollection frm)
    {
        UserModels candidate = new UserModels
        {
            userName = frm["userName"].ToString(),
            passWord = frm["passWord"].ToString()
       };

       DBSEntities context = new DBSEntities();
       UserName user = new UserName();
       context.AddToUserNames(user);
       context.SaveChanges();
       return View();
    }

Problem : I want to validate, whether the user input the both, user name and password textbox or not. But all of my above code, the user still can submit it without any validate message. I included the scripts to Site.Master ready. Anyone can tell me, what did I wrong?

Thanks.

  • 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-06T09:25:23+00:00Added an answer on June 6, 2026 at 9:25 am

    One thing is that you are not checking the model state during your POST and really should be using strongly typed Controller/Actions and Views. Even once you get ClientValidation working, you should still do a server side check to ensure that the client stuff was not bypassed. You could change your POST method to the following

     [HttpPost]
            public ActionResult UserMaintenance(UserModels candidate)
            {
                //If the model is not valid, return the view with the posted values
                //Validation messages will appear where appropriate based on your 
                //View Model
                if(!modelState.isValid()){
                   return View(candidate);
                }
    
                DBSEntities context = new DBSEntities();
                //Not sure what this code was doing, you were creating a variable
                //and then never setting the properties from the FormCollection on 
                //this new variable.  This seems to be the correct way below, but
                //whatever you need to do to get this POSTed info to your DB....
                context.AddToUserNames(candidate);
                context.SaveChanges();
                return View();
        }
    

    As far as the ClientSideValidation stuff, double check that you have included the proper scripts and in the proper order (can you list those out in your question?)

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

Sidebar

Related Questions

I am using custom model binder in ASP.NET MVC 2 that looks like this:
Solved using this post: Can you convert an ASP.NET MVC Application to a Web
I've wrote custom model binder in project, that uses ASP.NET MVC 2. This model
I am creating a model binder to use with asp.net mvc. This is what
I have a web service in asp.net and I have this model to return:
I am developing a medium sized ASP.NET project using ASP.NET MVC and Entity Framework.
We found a problem while accessing the Web service from our ASP.Net MVC project
In my recent project which is using Asp.net Mvc 2, we found that the
I am working a little project for myself using ASP.Net MVC 2 Preview 2
I've started using Ninject in an ASP.NET MVC 3 project, using the standard boot

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.