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

The Archive Base Latest Questions

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

I have a Razor web page where I have a model public class UploadModel

  • 0

I have a Razor web page where I have a model

public class UploadModel
{
    [Required]
    [StringLength(25)]
    public string PatientID { get; set; }
    [DataType(DataType.Date)]
    [DateRange("1000/12/01", "4010/12/16")]
    public DateTime DrawDate { get; set; }
}
public class DateRangeAttribute : ValidationAttribute
{
    private const string DateFormat = "yyyy/MM/dd";
    private const string DefaultErrorMessage =
    "'{0}' must be a date between {1:d} and {2:d}.";

    public DateTime MinDate { get; set; }
    public DateTime MaxDate { get; set; }

    public DateRangeAttribute(string minDate, string maxDate)
        : base(DefaultErrorMessage)
    {
        MinDate = ParseDate(minDate);
        MaxDate = ParseDate(maxDate);
    }

    public override bool IsValid(object value)
    {
        if (value == null || !(value is DateTime))
        {
            return true;
        }
        DateTime dateValue = (DateTime)value;
        return MinDate <= dateValue && dateValue <= MaxDate;
    }
    public override string FormatErrorMessage(string name)
    {
        return String.Format(CultureInfo.CurrentCulture,
        ErrorMessageString,
        name, MinDate, MaxDate);
    }

    private static DateTime ParseDate(string dateValue)
    {
        return DateTime.ParseExact(dateValue, DateFormat,
        CultureInfo.InvariantCulture);
    }
}

That does validation for the datetime

However in the view,
when I run through all the elements in the model

@Html.EditorFor(m => m)

It is creating a datetime type which creates problems because I am using jquery to do the calendar date picking since it is cross broswer. Any way to force the datetime to become a text even with the validation class? 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-12T09:25:27+00:00Added an answer on June 12, 2026 at 9:25 am

    Since you are writing your custom validation, why don’t you change

    public DateTime DrawDate { get; set; }
    

    to a string type and adjust your validation accordingly?

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

Sidebar

Related Questions

The Problem When I try to get to my ASP.NET Web Page Razor pages
I have an ASP.NET MVC 3 (Razor) Web Application, with a particular page which
I have an aspx web page that renders correctly. When converted to razor, it
I have the following class... public class Product { public int Id { get;
I am developing an ASP.Net MVC 3 Web application using Razor Views. I have
I have the following code in a CSHTML razor page: @{ var sort =
I have searched Codeplex, NuGet and Google with system.web.razor +source and I cannot find
I have some tabs at the top of a web page: home, features, contact,
Having done everything I have found I still cannot get Razor Intellisense to work
I have a MVC 3 Razor web application that needs to allow creating and

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.