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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T16:37:02+00:00 2026-05-21T16:37:02+00:00

I try to implement new validationrules in my MVC-Project but i wont become a

  • 0

I try to implement new validationrules in my MVC-Project but i wont become a validation-errormsg in my view.
What is wrong with the code? I have googlet alot and thought i have done all right -.-

WebConfig:

<appSettings>
  <add key="ClientValidationEnabled" value="true"/> 
  <add key="UnobtrusiveJavaScriptEnabled" value="true"/> 
</appSettings>

Model:

public class Model1 : IValidatableObject
{
    [Required]
    [DisplayFormat(DataFormatString="{d:0}", ApplyFormatInEditMode=true)]
    public DateTime Wunschtermin { get; set; }

    public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
    {
        if (Wunschtermin < DateTime.Now) yield return new ValidationResult("error1!", new[] { "Wunschtermin" });
        if (Wunschtermin.Date > DateTime.Today.AddYears(2)) yield return new ValidationResult("error2", new[] { "Wunschtermin" });
    }
    ...

View:

@model TestMvcApplication.Models.Model1

<h2>Create</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>
    ...
        <div class="editor-field">
            @Html.EditorFor(model => model.Wunschtermin)
            @Html.ValidationMessageFor(model => model.Wunschtermin)
        </div>
    ...

Edit:

Maybe I can override the RangeAttribute and avoid the problem:

[Range (DateTime.Now, DateTime.Today.AddYears(2))]

usefull?

  • 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-21T16:37:02+00:00Added an answer on May 21, 2026 at 4:37 pm

    have solved it myself, the code in the Controler was wrong:

        [HttpPost]
        public ActionResult Create(FormCollection collection)
    

    with a smal change:

        [HttpPost]
        public ActionResult Create(Model1 collection)
    

    it works well 🙂

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

Sidebar

Related Questions

I'm quite new to android and try to implement http client to communicate to
I try to implement a build pipeline using TFS. We already have TFS building
I'm new to android development and as a pet project I wanted to try
Can someone (hopefully Rob) explain how to implement the new SubSonicRepository<> Pattern? I have
I try implement advance on my question form here: send parameter from view-model to
I have a big problem with a java program. I try to implement a
WPF, Shapes I have a custom Shape , and try to implement MouseClick and
I try to implement simple touch event handling on Blackberry 9550 emulator, but it
Given the following code, I try to implement the public static Point operator +(int
I try to add an addons system to my Windows.Net application using Reflection; but

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.