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 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

Ask A Question

Stats

  • Questions 212k
  • Answers 213k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can put your function like this: <%= Ajax.ActionLink("YourAction",new AjaxOptions{… May 12, 2026 at 10:28 pm
  • Editorial Team
    Editorial Team added an answer According to this paper, it is like you said: It… May 12, 2026 at 10:28 pm
  • Editorial Team
    Editorial Team added an answer I don't know of any sort of "disabled" state. However,… May 12, 2026 at 10:28 pm

Related Questions

I'm trying to setup xVal with an ASP.NET MVC 2 Preview 1 project. I'm
I am getting the following error when I post back a page from the
I am working on a website that will post a JSON object (using jQuery
The task is simple: on the server side (python) accept an HTTP POST which

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.