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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:45:03+00:00 2026-05-31T04:45:03+00:00

I have the following View code: @using (Html.BeginForm(Login, Press, FormMethod.Post)) { <fieldset> <legend>User Registration</legend>

  • 0

I have the following View code:

@using (Html.BeginForm("Login", "Press", FormMethod.Post))
{
<fieldset>
    <legend>User Registration</legend>
    <div>
        @Html.TextBoxFor(model => model.FullName)
        @Html.ValidationMessageFor(model => model.FullName)
    </div>
    <div>
        @Html.TextBoxFor(model => model.Company)
        @Html.ValidationMessageFor(model => model.Company)
    </div>
    <div>
        @Html.TextBoxFor(model => model.EmailAddress)
        @Html.ValidationMessageFor(model => model.EmailAddress)
    </div>
    <div>
        @Html.CheckBoxFor(model => model.JoinMailingList)
        Please check this box to recieve a seasonal look book pdf and monthly newsletter
    </div>
    <p>
        <input type="submit" value="Proceed" />
    </p>
</fieldset>
}

And here is my Model:

public class UserViewModel
{
    [Required(ErrorMessage = "Please enter your name.")]
    [MaxLength(100)]
    public string FullName { get; set; }

    [Required(ErrorMessage = "Please enter the name of your company.")]
    [MaxLength(50)]
    public string Company { get; set; }

    [Required(ErrorMessage = "Please enter your email.")]
    [DataType(DataType.EmailAddress)]
    [RegularExpression(@"^(([A-Za-z0-9]+_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\.+)|([A-Za-z0-9]+\++))*[A-Za-z0-9]+@((\w+\-+)|(\w+\.))*\w{1,63}\.[a-zA-Z]{2,6}$", ErrorMessage = "Please enter a valid email address.")]
    [MaxLength(255)]
    public string EmailAddress { get; set; }

    public bool JoinMailingList { get; set; }
}

The problem is that when I click on the ‘Proceed’ button, none of the validation occurs. It just posts the action with no validation performed on it? Do I have to perform this inside the Controller?

Here is my Controller code:

public class PressController : Controller
{
    //
    // GET: /Press
    public ViewResult Index()
    {
        return View();
    }

    //
    // GET: /Press/Login
    public ViewResult Login()
    {
        return View();
    }

    [HttpPost]
    public ActionResult Login(UserViewModel userViewModel)
    {
        return RedirectToAction("Index", "Press");
    }
}
  • 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-31T04:45:04+00:00Added an answer on May 31, 2026 at 4:45 am

    Make sure that the action you are posting to takes the view model as argument:

    [HttpPost]
    public ActionResult Press(UserViewModel model)
    {
        // at this stage the validation has been performed during
        // the process of model binding and now you could look in the 
        // modelstate if the model is vaild:
    
        if (!ModelState.IsValid) 
        {
            // validation failed => redisplay the view so that the user
            // can fix his errors. 
            // Note that calling ModelState.IsValid doesn't trigger any validation
            return View(model);
        }
    
        // at this stage we know that validation passed => we could do some processing
        // and redirect
    
        return RedirectToAction("Success");
    }
    

    or some people also use the TryUpdateModel method which also allows you to perform model binding which triggers the validation:

    [HttpPost]
    public ActionResult Press()
    {
        var model = new UserViewModel();
        // validation will be triggered at this stage and the method
        // will return true or false based on the result of this validation
        if (!TryUpdateModel(model))
        {
            // validation failed => redisplay the view so that the user
            // can fix his errors. 
            return View(model);
        }
    
        // at this stage we know that validation passed => we could do some processing
        // and redirect
    
        return RedirectToAction("Success");
    }
    

    And if you want to enable client side validation, just make sure that the following 2 scripts are referenced in your page:

    <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>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code in a MVC view: <% using (Html.BeginForm()) { %>
I have the following in my view: <%using (Html.BeginForm()) {%> <% foreach (var item
I have the following code in my view: <% using (Ajax.BeginForm(JsonCreate, new AjaxOptions {
In my html I have <h2>Title goes here</h2> @using (Html.BeginForm(Action, Controller, FormMethod.Post, new {
I have the following code in a partial view (using Spark): <span id=selectCount>0</span> video(s)
I have created an alert view with two buttons using the following code: UIAlertView
I Have following code: Controller: public ActionResult Step1() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public
i have the following code in an asp.net mvc view. <% = Html.DropDownList(Filter, new
I have following view <asp:Content ID=Content2 ContentPlaceHolderID=MainContent runat=server> <h2>Tables <%=ViewData[RetriverName] %></h2> <%using (Html.BeginForm(ResfreshSelectedTables, Home))
I have the following form in a partial view @model PartDetail @using (Ajax.BeginForm(Create, Part,

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.