{"action":"created","issue":{"url":"https://api.github.com/repos/aspnet/Mvc/issues/4105","repository_url":"https://api.github.com/repos/aspnet/Mvc","labels_url":"https://api.github.com/repos/aspnet/Mvc/issues/4105/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/Mvc/issues/4105/comments","events_url":"https://api.github.com/repos/aspnet/Mvc/issues/4105/events","html_url":"https://github.com/aspnet/Mvc/issues/4105","id":133975334,"number":4105,"title":"Extend asp-for with prefixing ","user":{"login":"lothistvan","id":5110980,"avatar_url":"https://avatars.githubusercontent.com/u/5110980?v=3","gravatar_id":"","url":"https://api.github.com/users/lothistvan","html_url":"https://github.com/lothistvan","followers_url":"https://api.github.com/users/lothistvan/followers","following_url":"https://api.github.com/users/lothistvan/following{/other_user}","gists_url":"https://api.github.com/users/lothistvan/gists{/gist_id}","starred_url":"https://api.github.com/users/lothistvan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lothistvan/subscriptions","organizations_url":"https://api.github.com/users/lothistvan/orgs","repos_url":"https://api.github.com/users/lothistvan/repos","events_url":"https://api.github.com/users/lothistvan/events{/privacy}","received_events_url":"https://api.github.com/users/lothistvan/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2016-02-16T12:58:06Z","updated_at":"2016-02-16T22:05:20Z","closed_at":"2016-02-16T22:05:20Z","body":"I use same Address class in many models: Employe.MailingAddress, Company.PhisycalAddress, Company.BillingAddress, etc. I'd like to create a ViewComponent to generate Address fields into forms.\r\nCode of ViewComponent is very simple:\r\n\r\n```\r\n    public class AddressViewComponent : ViewComponent\r\n    {\r\n        public IViewComponentResult Invoke(AddressViewModel model)\r\n        {\r\n            return View(model);\r\n        }\r\n    }\r\n```\r\n\r\nDefault.cshtml:\r\n```\r\n@model AddressViewModel\r\n\r\n<div class=\"form-group row\">\r\n    <label asp-for=\"Country\" class=\"col-md-3\"></label>\r\n    <column class=\"col-md-9\">\r\n        <input asp-for=\"Country\" />\r\n        <span asp-validation-for=\"Country\"></span>\r\n    </column>\r\n</div>\r\n<div class=\"form-group row\">\r\n    <label asp-for=\"City\" class=\"col-md-3\"></label>\r\n    <column class=\"col-md-9\">\r\n        <input asp-for=\"City\" />\r\n        <span asp-validation-for=\"City\"></span>\r\n    </column>\r\n</div>\r\n...\r\n```\r\nAnd I invoke this component from view :\r\n```\r\n<form ...>\r\n...\r\n<span>Home address:</span>\r\n@Component.Invoke(\"Address\", Model.HomeAddress)\r\n<span>Mailing address:</span>\r\n@Component.Invoke(\"Address\", Model.MailingAddress)\r\n\r\n</form>\r\n```\r\nThe problem: asp-for generates names and id-s without the original property name - and this is the correct method because in the component there is no complex property. My suggestion is a new taghelper: \"asp-for-propertyname\" or \"asp-for-prefix\" (or something similar) to let us decorate the generated identifiers with prefix - as in case of complex model properties. \r\n\r\nThe code below\r\n```\r\n<input asp-for=\"Country\" asp-for-propertyname=\"HomeAddress\" />\r\n```\r\nshould generates the following output:\r\n```\r\n<input type=\"text\" name=\"HomeAddress.Country\" id=\"HomeAddress_Country\" />\r\n```"},"comment":{"url":"https://api.github.com/repos/aspnet/Mvc/issues/comments/184893301","html_url":"https://github.com/aspnet/Mvc/issues/4105#issuecomment-184893301","issue_url":"https://api.github.com/repos/aspnet/Mvc/issues/4105","id":184893301,"user":{"login":"lothistvan","id":5110980,"avatar_url":"https://avatars.githubusercontent.com/u/5110980?v=3","gravatar_id":"","url":"https://api.github.com/users/lothistvan","html_url":"https://github.com/lothistvan","followers_url":"https://api.github.com/users/lothistvan/followers","following_url":"https://api.github.com/users/lothistvan/following{/other_user}","gists_url":"https://api.github.com/users/lothistvan/gists{/gist_id}","starred_url":"https://api.github.com/users/lothistvan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lothistvan/subscriptions","organizations_url":"https://api.github.com/users/lothistvan/orgs","repos_url":"https://api.github.com/users/lothistvan/repos","events_url":"https://api.github.com/users/lothistvan/events{/privacy}","received_events_url":"https://api.github.com/users/lothistvan/received_events","type":"User","site_admin":false},"created_at":"2016-02-16T22:05:20Z","updated_at":"2016-02-16T22:05:20Z","body":"Thank you very much! The TemplateInfo solves my problem The following code denerates the correct name for inputs:\r\n\r\n```\r\n@model MyProject.Web.Components.Address.AddressViewModel\r\n@{\r\n    ViewContext.ViewData.TemplateInfo.HtmlFieldPrefix = Model.PropertyName;\r\n}\r\n\r\n<div class=\"form-group row\">\r\n    <label asp-for=\"Country\" class=\"col-md-3\"></label>\r\n    <column class=\"col-md-9\">\r\n        <input asp-for=\"Country\" />\r\n        <span asp-validation-for=\"Country\"></span>\r\n    </column>\r\n</div>\r\n...\r\n```"}}