Quantcast
Channel: ASPNETWebStack Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 7215

Commented Issue: GetClientValidationRules() needs the container passed in [1528]

$
0
0

// Copied from https://aspnet.codeplex.com/workitem/5137
// Vote number : 18
// Attached file : [MvcApplication3.zip
](https://www.codeplex.com/Download/AttachmentDownload.ashx?ProjectName=aspnet&WorkItemId=5137&FileAttachmentId=462903)

Please modify "ValidationExtensions.ApplyFieldValidationMetadata" so that "htmlHelper.ViewData.Model" gets passed into "v.GetClientValidationRules". The footprint for "GetClientValidationRules" will need to be modified to include "object container". This will make "GetClientValidationRules" consistent with its sister method "Validate(object container)". The container is often necessary for determining how to validate. I downloaded the source to verify that this is a small and workable change.

I've attached a project that demonstrates the problem and the ugly hack required to work around it. Look in Models\Request.cs. Essentially I had to make a provider, override CreateMetadata, and add the last container created into the AdditionalValues collection. This is related to bug #5117. I should not have had to do anything with DataAnnotationsModelMetadata to make this work.
Comments: Changing GetClientValidationRules will be a breaking change. Modifying TypeDescriptor to return the "Rules engine" would require changing public static ICustomTypeDescriptor Get(Type type) that would be a breaking change. I think the right approach here is to create a custom ModelValidatorProvider. The one based on DataAnnotations is not intended to work with rules decided at runtime and i'm not confident it would be a good idea to change it to support those scenarios.

Viewing all articles
Browse latest Browse all 7215

Trending Articles