{"action":"created","issue":{"url":"https://api.github.com/repos/aspnet/Mvc/issues/5028","repository_url":"https://api.github.com/repos/aspnet/Mvc","labels_url":"https://api.github.com/repos/aspnet/Mvc/issues/5028/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/Mvc/issues/5028/comments","events_url":"https://api.github.com/repos/aspnet/Mvc/issues/5028/events","html_url":"https://github.com/aspnet/Mvc/issues/5028","id":165749514,"number":5028,"title":"replacement for html.GetUnobtrusiveValidationAttributes html.GetClientValidationRules","user":{"login":"omuleanu","id":2010805,"avatar_url":"https://avatars.githubusercontent.com/u/2010805?v=3","gravatar_id":"","url":"https://api.github.com/users/omuleanu","html_url":"https://github.com/omuleanu","followers_url":"https://api.github.com/users/omuleanu/followers","following_url":"https://api.github.com/users/omuleanu/following{/other_user}","gists_url":"https://api.github.com/users/omuleanu/gists{/gist_id}","starred_url":"https://api.github.com/users/omuleanu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/omuleanu/subscriptions","organizations_url":"https://api.github.com/users/omuleanu/orgs","repos_url":"https://api.github.com/users/omuleanu/repos","events_url":"https://api.github.com/users/omuleanu/events{/privacy}","received_events_url":"https://api.github.com/users/omuleanu/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2016-07-15T09:47:19Z","updated_at":"2016-07-18T20:54:01Z","closed_at":null,"body":"hi\r\nin mvc 5 there was html.GetUnobtrusiveValidationAttributes\r\nin rc1 I think there was html.GetClientValidationRules\r\nnow, I can't find anything that will return the same \r\n\r\nI'm developing a custom helper and I need to get the client validation attributes"},"comment":{"url":"https://api.github.com/repos/aspnet/Mvc/issues/comments/233455441","html_url":"https://github.com/aspnet/Mvc/issues/5028#issuecomment-233455441","issue_url":"https://api.github.com/repos/aspnet/Mvc/issues/5028","id":233455441,"user":{"login":"dougbu","id":6431421,"avatar_url":"https://avatars.githubusercontent.com/u/6431421?v=3","gravatar_id":"","url":"https://api.github.com/users/dougbu","html_url":"https://github.com/dougbu","followers_url":"https://api.github.com/users/dougbu/followers","following_url":"https://api.github.com/users/dougbu/following{/other_user}","gists_url":"https://api.github.com/users/dougbu/gists{/gist_id}","starred_url":"https://api.github.com/users/dougbu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dougbu/subscriptions","organizations_url":"https://api.github.com/users/dougbu/orgs","repos_url":"https://api.github.com/users/dougbu/repos","events_url":"https://api.github.com/users/dougbu/events{/privacy}","received_events_url":"https://api.github.com/users/dougbu/received_events","type":"User","site_admin":false},"created_at":"2016-07-18T20:54:01Z","updated_at":"2016-07-18T20:54:01Z","body":"If looking for the attributes a specific helper would add, could do something like I showed above but with\r\n``` c#\r\nvar dictionary = tagBuilder.Attributes\r\n    .Where(item => item.Key.StartsWith(\"data-\", StringComparison.OrdinalIgnoreCase))\r\n    .ToDictionary(keySelector: item => item.Key, elementSelector: item => item.Value);\r\n```\r\n\r\nCould also subclass `DefaultHtmlGenerator` e.g.\r\n``` c#\r\npublic class MyHtmlGenerator : DefaultHtmlGenerator\r\n{\r\n    public MyHtmlGenerator(\r\n        IAntiforgery antiforgery,\r\n        IOptions<MvcViewOptions> optionsAccessor,\r\n        IModelMetadataProvider metadataProvider,\r\n        IUrlHelperFactory urlHelperFactory,\r\n        HtmlEncoder htmlEncoder,\r\n        ClientValidatorCache clientValidatorCache)\r\n        : base(\r\n              antiforgery,\r\n              optionsAccessor,\r\n              metadataProvider,\r\n              urlHelperFactory,\r\n              htmlEncoder,\r\n              clientValidatorCache)\r\n    {\r\n    }\r\n\r\n    public new void AddValidationAttributes(...)\r\n    {\r\n        // ...\r\n    }\r\n}\r\n```\r\nThen place `MyHtmlGenerator` in DI and use it from your extension methods e.g.\r\n``` c#\r\nvar generator = helper.ViewContext.HtmlContext.RequestServices.GetRequiredService<IHtmlGenerator>() as MyHtmlGenerator\r\n```\r\n\r\nUnfortunately `ClientValidatorCache` was placed it in an `.Internal` namespace. This implies nothing about it can be relied upon. Might be better to create a wrapper class that delegates to the default `IHtmlGenerator` but is itself registered without reference to that interface."}}
{"actor":{"display_login":"dougbu"}}