.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Data Annotation not triggering the client side validation when used on an overriden model property

Posted By:      Posted Date: September 10, 2010    Points: 0   Category :ASP.Net
Hi all, This is a saga from a post that was recently answered:http://forums.asp.net/t/1598187.aspxMy main problem is the lack of client side validation when we use a child model class, the server side validation works like a charm whether you use the virtual/override solution or the new attribute on the child class with the getter and setter linking the property to the base class's one.The client side validation does not work with none of the solutions presented below.This is a sample code of the first solution: [Serializable] public class DateViewModel { ... [Display(typeof(App_GlobalResources.Messages), "Date_Year")] public virtual int? Year { get; set; } ... } [Serializable] public class BirthDateViewModel : DateViewModel { ... [Display(typeof(App_GlobalResources.Messages), "Date_Year")] [YearRange(ErrorMessageResourceType = typeof(App_GlobalResources.Messages), ErrorMessageResourceName = "Validation_Range")] public override int? Year { get; set; } ... } This is a code sample of the second solution : [Serializable] public class DateViewModel { ... [Display(typeof(App_GlobalResources.Messages), "Date_Year")] public int? Year { get; set; } ... } [Serializable] public class BirthDateViewModel : DateViewMod

View Complete Post

More Related Resource Links

Client Side Validation - suppressing specific property errors


Hi there,

I have implemented some Client Side Validation in MVC via <%Html.EnableClientValidation(); %> I am using Metadata Descriptions an EF and it's working fine but one thing is driving me crazy!!

I have a Price field that is a number (double) and I have some metadata errors for it for range and required but MVC is adding in this validation "The field Price must be a number." which would be fine except!! when I type 20.     (note the decimal point) this validation fails with a popup "The field Price must be a number." then when I type another number e.g. 20.0 it goes away again.

Is there some way to ignore/suppress non custom property validation errors??



How to display model level custom data annotation validation error?


Hello Experts,

I am a MVC newbie & am lost in various ways validation can be implemented in my application.

I created a custom model-level data annotation validator attribute, but am unable to display its error message in the view. Basically, I have let's say 5 properties in the Entity class Job (model-level custom attribute called UniqueKeywords defined on it):

1) LoginID: value comes in the URL

2) Title: Required property level attribute defined on it

3) CatID1, CatID2, CatID3 - 3 categoryIDs - these are dropdowns in the view with same list of keywords in all 3.

I want to mandate that the values picked by the user in all 3 category dropdowns should be different.

With reference to the code pasted below, here is the explanation of what happens:

When I submit the form without specifying a title or picking anything from any of the 3 category dropdowns, the validation occurs for the property level Required attribute as well as model level uniquekeywords attribute, but the error is displayed only next to the required field "Title". I can confirm that the custom validation also works by filling in some text in the Title field & then re-posting the form...this re-displays the view, but the error message "Category cannot be duplicated" is not displayed.

Looks like I am missing s

Client Side Data Manipulation


I have a web page that displays a listing of links.  A treeview control displays a hierarchy of tags with checkboxes that act as filters... when checked,  the list is 'filtered'.  This all works fine but what I really need is for this page to be lightning fast.  Right now, checking a box fires an event and a postback, etc.   I'm wondering if there is a way to do all of this on the client side.  For example, could you start out with a complete listing (dataset) of all possible hyperlinks,  and then apply filters to that list all on the client side so as to eliminate any lag/postback?    

Module 5: Accessing SharePoint 2010 Data with Client-Side APIs

SharePoint 2010 provides a new client object model that enables you to create SharePoint solutions that run remotely from the SharePoint server farm.

Video: SharePoint 2010 Data and the Client Object Model

This video provides an overview of how to use the client object model from a Windows Presentation Foundation application. (Length: 5:38)

Server-side validation on an Entity Framework required field (property) does not work!

Has anyone had issues getting server-side validation on an Entity Framework required field (property) to work? The data type is a string (nvarchar). Server-side validation for required fields of other data types WORK fine. Only string fields have issues. I get the following error on UpdateModel(obj); of my POST method within the controller. Exception Details: System.Data.ConstraintException: This property cannot be set to a  null value.Source Error: Line 4500:                OnTextChanging(value);Line 4501:                ReportPropertyChanging("Text");Line 4502:                _Text = StructuralObject.SetValidValue(value, false);Line 4503:                ReportPropertyChanged("Text");Line 4504:                OnTextChanged(); I've even tried data annotations like this but it seems to get ignored.     [MetadataType(typeof(ObjMD))]     public partial class Obj     {    

javascript pageLoad() & client side isPostBack property?

Hello and thanks for your help in advance. I have some javascript code that I have placed in the pageLoad() function like this:function pageLoad() { var x = 5; }But I only want this to happen on the first time the page loads... Is there an isPostBack property on the client site?

CheckBoxList client-side validation

How can I validate on client side if a CheckBoxList has at least one item? (is not empty)

Dynamically (on client side) populating data control (repeater) when dropdown item is selected

Hello!I'm currently working on a project and I want to make as much things as possible performing on client side - with as little loading as possible.The project consist of three "main" pages. On one page I use jQuery DataTable plugin which is working great. One page has tabs (using jQuery). I want to put datacontrol (repeater) on this site and when  user selects one item in dropdown, data in repeater loads on client side, without performing the action on server.I wonder if this is possible and if somebody can give me some case to help with?Thanks!I hope I was clear enough. all the best

Say if ajax is forbidden on the client side,how can we still get the requred data back?

    <p>        <%using (Ajax.Form("ExamineTextBox", new AjaxOptions { UpdateTargetId = "result" }))         { %>             <%= Html.TextBox("textBox1")%>             <input type="submit" value="Button"/>              <span id="result"/>      <% } %>     </p>code slice of a sample view page(notice "Ajax.Form"):  <p>       <%using (Ajax.Form("ExamineTextBox", new AjaxOptions { UpdateTargetId = "result" }))        { %>            <%= Html.TextBox("textBox1")%>            <input type="submit" value="Button"/>             <span id="result"/>     <% } %>    </p>But if ajax request functionality is disabled/forbidden on the client side, I still wanna carry on the request , maybe in a normal http request way(mean refresh the whole page instead to at least get the data back). Is it

Client side validation using Client OM in sharepoint 2010

Hi, Can we use Client Object Model for Client side validation? Suppose, i have a SharePoint 2010 List. While adding a new item in that list, i want to check for Title is already available or not, person has posted any item earlier or not..that kind of stuff. Could i check this at client side rather than ItemAdding Event, so that i can reduce the network traffic? Thanks in advanced. Hardik Shah Solution Developer.

Client Side Validation with jQuery


I have used client side validation with Ajax before.  Now I need to do client side validation with jQuery.

I am referencing jQuery 1.4.2 and jQuery.validation version 1.7.

I have added <% Html.EnableClientValidation(); %> to the view.

I have added Html.TextBoxFor and Html.ValidationMessageFor to the view.

Client side validation still does not work.

If I understand correctly, I also need to include MicrosoftMvcJQueryValidation.js.  This file was not installed with VS 2010 ultimate.  I have heard that it is available on the Futures project, but the links to the site are broken.

Do I need MicrosoftMvcJQueryValidation.js to make client side validation work?

If so, where do I find the current version of MicrosoftMvcJQueryValidation?  Why isn't it readily available for download or included with VS 2010?

If not, what do I do next to get client side validation to work?

I know that I could manually add calls to jQuery validation, but that is far from ideal - especially since the Ajax v

Expose data contract used in two services as a single type on client side?


I have a .dll that contains my data contracts and I reference this dll in two different services.

Now, on the client side I don't want to add this dll because I need both WPF-clients and Silverlight clients. So, what I want is to be able to use a single data contract on the client side and not with different namespaces for the different services. As I understand this should be possible but I don't know how.

Can someone explain how I can generate a single data contract on client side that can be used for calls to both services?

Thanks for help!

IDataErrorInfo client side validation


Is there a way for client side validation while using IDataErrorInfo?

Validation of model in side model


Hello Everyone,

I have recently started working on ASP.NET with MVC 2 framework, and I am facing following difficulty in validating my data,


In my application the view (ASPX) is divided into tabs (jQuery) and each tab's content is ViewUserControl (ASCX). The main model for the view has collection of sub models for individual tabs. I use RenderPartial method to render view user control.

            <div id="divPage1" class="tabs">
                <% Html.RenderPartial("Tab1", Model.Tabs["Tab1"]); %>

And the user control (Tab1.ascx) refers the specific model for it,

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<NDTMS.Models.Tab1Model>" %>
<table width="100%" align="left" style="caption-side: top" class="details">
            <%= Html.LabelFor(m => m.FirstName) %>
             <%= Html.TextBoxFor(m => m.FirstName) %>

           <%= Html.ValidationMessageFor(m => m.FirstName) %>

            <%= Html.LabelFor(m =&g

Client-side validation confusion


There are three dropdownlists on one of the Views in my MVC application. If I try to submit the form before they have values, I get error messages for each, stating that they're required fields and they have the red border applied. All that is well and good, except that I don't have them marked with required attributes! Now I'm very confused as to where the rule is being applied, but haven't been able to track it down. Here's the View:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<DSC.Data.Model.Admin.UserMgmt.AddNewUserContainer>" %>

<% using (Html.BeginForm("AddNewUser", "UserMgmt", FormMethod.Post)) { %>
                NT Login:
                <%: Html.HiddenFor(nt => nt.UserToAdd.NTLogin) %>

                <%: Model.UserToAdd.NTLogin %>
                First Name:
                <%: Html.EditorFor(model => model.UserToAdd.FirstName) %>
                <%: Html.ValidationMessageFor(model => model.UserToAdd.FirstName) %>
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend