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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:14:07+00:00 2026-05-27T06:14:07+00:00

Using MVC3 Razor, I have a partial view with some text, two text boxes

  • 0

Using MVC3 Razor, I have a partial view with some text, two text boxes (StartDate & EndDate), a Cancel and a Search button.

When invalid dates are entered into the StartDate and EndDate textboxes, the textboxes highlight red with the unobstrusive decoration the datepicker uses?

I cannot figure out how to require these fields and highlight them red as the invalid data entry does.

Here is my code

<script type="text/javascript">
$(document).ready(function () {
    $('.date').datepicker({ dateFormat: "mm/dd/yy" });

    $("#printnoteform").validate({
        rules: {
            startdate: {
                required: true
            },
            enddate: {
                required: true
            }
        },
        messages: {
            startdate: {
                required: "Required"
            },
            enddate: {
                reqquierd: "Required 2"
            }
        }
    });
});
</script>

The form…

@using (Html.BeginForm("PrintNotes", "Note", FormMethod.Post, new { id = "printnoteform", name = "printnoteform" }))
{
    ......

HTML for StartDate & EndDate

<input type="text" id="startdate" name="startdate" class="date" />
<input type="text" id="enddate" name="enddate" class="date" />

I have no browser errors, StartDate and EndDate are not part of a model and I don’t want to make one if I don’t have to. Web.config is setup properly.

What am I missing?

  • 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-27T06:14:08+00:00Added an answer on May 27, 2026 at 6:14 am

    You have two mutually exclusive possibilities:

    1. Use jquery unobtrusive
    2. Manually hook up the validation rules of the form

    If you want to use jquery unobtrusive you shouldn’t be manually adding any .validate rules to your form (as you did). This is done automatically by the jquery unobtrusive script. Of course for it to be able to do it your input fields should be decorated with HTML5 data-* attributes in order to indicate the rules and messages to use. For example:

    <input class="text-box single-line" data-val="true" data-val-required="The startdate field is required." id="startdate" name="startdate" type="text" value="" />
    <input class="text-box single-line" data-val="true" data-val-required="The enddate field is required." id="enddate" name="enddate" type="text" value="" />
    

    Normally this is the output that standard Html helpers such as EditorFor generate when you use a view model and bind to its properties. They use Data Annotations on your view model to infer the validation rules and transpose them as data-* attributes.

    The second possibility is to manually hook up the validation rules. In this case you should remove any traces of the jquery unobtrusive script as it will conflict with your .validate rules on the form. It is up to you in this case to define the rules and messages.

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

Sidebar

Related Questions

I have a simple PartialView setup in my MVC3 Project using the Razor View
'm using ASP.NET MVC 3 with Razor views. I have a partial view which
I have an existing SqlConnection conn; in some controller (using ASP.NET MVC3 + Razor
I am trying to render the following HTML using an MVC3 Razor View: <input
I have a string created using asp.net MVC3 Razor block like this: @{ var
I'm building a website using MVC3, EF, and Razor and I currently have the
I have an href in my asp.net MVC3 Razor view and I want to
Here's the issue at hand: I have developed an ASP.NET MVC3 application using Razor.
I'm using the Razor view engine with MVC3 RC1 and Razor, and running through
I'm using MVC3 w/ Razor and I have a model that has quite a

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.