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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:42:13+00:00 2026-05-27T15:42:13+00:00

Basically, I have correctly followed different tutorials. Now, my models are taken from a

  • 0

Basically, I have correctly followed different tutorials. Now, my models are taken from a library file (dll) which shouldnt be a problem as everything else functions fine.

My model:

public class RoomBookingInsert
{

    public Int32 CostCentreNo { get; set; }
    public Int32 CustomerAccNo { get; set; }
    public Int32 RoomNo { get; set; }
    public Int32 ServiceCode { get; set; }
    [PriceValidation]
    public Decimal HourlyRate { get; set; }
    [DataType(DataType.Date)]
    [DateRange("2010/12/01", "2010/12/16")]
    public DateTime StartDate { get; set; }
}

The attributes ARE recognised, as they go blue accordingly, and autocomplete detects them. However, when I post my form, it accepts anything.

I have included my code below for validation attributes, and I recognise that this is server side, and so happens on the post command.

My Form in asp.net mvc3 using razor:

@model MyLibrary.RoomBookingInsert

@{
    ViewBag.Title = "Temp";
}

<h2>Temp</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)
    <fieldset>
        <legend>RoomBookingInsert</legend>

        @Html.EditorForModel()
        <p>
            <input type="submit" value="Save" />
        </p>
    </fieldset>
}

<div>
    @Html.ActionLink("Back to List", "Index")
</div>

Here is my first Price validation (ensuring that it never goes negative).

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;

    public class PriceValidationAttribute : ValidationAttribute

    {
        private decimal minPrice = 0.00M;
        private decimal maxPrice = 100.00M;

            public PriceValidationAttribute()
            {
            }
            public override bool IsValid(object value)
            {
                decimal price = (decimal)value;
                if (price < this.minPrice || price > this.maxPrice)
                    return false;
                return true;
            }

    }

Here is my Date Range validation:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations;
using System.Globalization;

    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);
        }

}
  • 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-27T15:42:14+00:00Added an answer on May 27, 2026 at 3:42 pm

    The page will not be automatically validated. In order to validate the page what you need to do on your controller is something like this:

    // Guessing your view is called Temp...
    public class TempController : Controller
    {
        // This method will create the view with the RoomBookingInsert model
        // NOTE: it has no HttpPost attribute
        public ActionResult Temp()
        {
             return View(new MyLibrary.RoomBookingInsert());
        }
    
        // This is the post back action method for your view
        // NOTE: this has an HttpPost attribute
        [HttpPost]
        public ActionResult Temp(MyLibrary.RoomBookingInsert model)
        {
            // Always start by checking the model state and if it is not valid
            // return the view with the original model
            if(!ModelState.IsValid)
            {
                return View(model);
            }
    
            // Rest of logic goes here
            ...
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I basically have a page which shows a processing screen which has been flushed
Ok, so basically I have a jspf template file with a backing FragmentBean that
I'm not sure if I created this topic correctly, but basically I have a
I basically have the core data and the app working correctly except for the
Basically, I have data of several people contained in a .csv file. This spreadsheet
Not quite sure if I asked correctly, but basically I have an array that
Basically i am trying to create a programme, which needs to have some authorisation.
Basically I have a Parent superclass which i.e is called MAMMAL. The mammal by
Basically, I currently have login/ in urls.py redirect to the django.contrib.auth.views.login and that seems
I basically have the following flow: XML -> JSON -> Spring MVC -> jsp

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.