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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:16:19+00:00 2026-05-12T09:16:19+00:00

I am following this post . Server side validations work as expected. But the

  • 0

I am following this post.

Server side validations work as expected. But the clientside validators are only getting generated for the ID field.

My Linq2Sql Entity Class has two properties ID & CategoryName and below is my Metadata class

[MetadataType(typeof(BookCategoryMetadata))]
public partial class BookCategory{}

public class BookCategoryMetadata
{
    [Required]
    [StringLength(50)]
    public string CategoryName { get; set; }
}

Method to add a category

/// <summary>
/// Adds the category.
/// </summary>
/// <param name="category">The category.</param>
public void AddCategory(BookCategory category)
{
    var errors = DataAnotationsValidationHelper.GetErrors(category);
    if (errors.Any()) {
        throw new RulesException(errors);
    }

    _db.BookCategories.InsertOnSubmit(category);
    _db.SubmitChanges();
}

Create action in the controller

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Create([Bind(Exclude = "ID")]BookCategory category)
{
    try {
        _repository.AddCategory(category);
    } catch (RulesException ex) {
        ex.AddModelStateErrors(ModelState, "");
    }

    return ModelState.IsValid ? RedirectToAction("Index") : (ActionResult)View();
}

And the view

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

<h2>Create</h2>

<%= Html.ValidationSummary("Create was unsuccessful. Please correct the errors and try again.") %>

<% using (Html.BeginForm()) {%>

    <fieldset>
        <legend>Fields</legend>
        <p>
            <label for="CategoryName">CategoryName:</label>
            <%= Html.TextBox("CategoryName") %>
            <%= Html.ValidationMessage("CategoryName", "*") %>
        </p>
        <p>
            <input type="submit" value="Create" />
        </p>
    </fieldset>

<% } %>

<div>
    <%=Html.ActionLink("Back to List", "Index") %>
</div>
<%= Html.ClientSideValidation<BookCategory>() %>

Now xVal only generates validation rules for the ID field.

<script type="text/javascript">xVal.AttachValidator(null, {"Fields":[{"FieldName":"ID","FieldRules":[{"RuleName":"DataType","RuleParameters":{"Type":"Integer"}}]}]})</script>

The server side validation for CategoryName works perfect. Why xVal is not generating validation rules for the CategoryName? What am I doing wrong?

  • 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-12T09:16:19+00:00Added an answer on May 12, 2026 at 9:16 am

    Supposedly, xVal 0.8 has buddy classes working. You can read this post here:

    [http://xval.codeplex.com/Thread/View.aspx?ThreadId=54300%5D%5B1%5D

    If that doesn’t fix your problem, try pulling down the latest code for xVal and modifying xVal.RuleProviders.PropertyAttributeRuleProviderBase::GetRulesFromTypeCore to be

     protected override RuleSet GetRulesFromTypeCore(Type type)
     {
       var typeDescriptor = metadataProviderFactory(type).GetTypeDescriptor(type);
       var rules = (from prop in typeDescriptor.GetProperties().Cast<PropertyDescriptor>()
                             from rule in GetRulesFromProperty(prop)
                             select new KeyValuePair<string, Rule>(prop.Name, rule));
    
       var metadataAttrib = type.GetCustomAttributes(typeof(MetadataTypeAttribute), true).OfType<MetadataTypeAttribute>().FirstOrDefault();
       var buddyClassOrModelClass = metadataAttrib != null ? metadataAttrib.MetadataClassType : type;
       var buddyClassProperties = TypeDescriptor.GetProperties(buddyClassOrModelClass).Cast<PropertyDescriptor>();
       var modelClassProperties = TypeDescriptor.GetProperties(type).Cast<PropertyDescriptor>();
    
       var buddyRules =  from buddyProp in buddyClassProperties
                                  join modelProp in modelClassProperties on buddyProp.Name equals modelProp.Name
                                  from rule in GetRulesFromProperty(buddyProp)
                                  select new KeyValuePair<string, Rule>(buddyProp.Name, rule);
    
       rules = rules.Union(buddyRules);
       return new RuleSet(rules.ToLookup(x => x.Key, x => x.Value));
     }
    

    Also, if this fixes your problem, you might want to contact Steve Sanderson and let him know this bug is still present.

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

Sidebar

Related Questions

I'm trying to implement routing such as the following: posts/535434/This-is-a-post-title posts/tagged/tags+here // Matches {controller}/{action}/{id}
I'm building a Windows service and following this MSDN article , but I'm stuck
I am getting the following error on the client side when I pass invalid
Following this question: Good crash reporting library in c# Is there any library like
Following this example, I can list all elements into a pdf file import pyPdf
I've been following this tutorial (lesson 6) in order to build and deploy a
So I am following this guide: http://technotes.1000lines.net/?p=23 and I am going through the steps.
I'm following this tutorial (seems good) for Rails. After I run ruby script/generate scaffold
I see lots of TDD practitioners following this cycle: 1) Write your test as
I have ASP.Net code similar to the following (this is inside a FIELDSET): <ol>

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.