{"action":"created","issue":{"url":"https://api.github.com/repos/aspnet/Mvc/issues/7850","repository_url":"https://api.github.com/repos/aspnet/Mvc","labels_url":"https://api.github.com/repos/aspnet/Mvc/issues/7850/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/Mvc/issues/7850/comments","events_url":"https://api.github.com/repos/aspnet/Mvc/issues/7850/events","html_url":"https://github.com/aspnet/Mvc/issues/7850","id":328520779,"node_id":"MDU6SXNzdWUzMjg1MjA3Nzk=","number":7850,"title":"asp-for is rendering child property value instead of parent","user":{"login":"data-handler","id":7189305,"node_id":"MDQ6VXNlcjcxODkzMDU=","avatar_url":"https://avatars0.githubusercontent.com/u/7189305?v=4","gravatar_id":"","url":"https://api.github.com/users/data-handler","html_url":"https://github.com/data-handler","followers_url":"https://api.github.com/users/data-handler/followers","following_url":"https://api.github.com/users/data-handler/following{/other_user}","gists_url":"https://api.github.com/users/data-handler/gists{/gist_id}","starred_url":"https://api.github.com/users/data-handler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/data-handler/subscriptions","organizations_url":"https://api.github.com/users/data-handler/orgs","repos_url":"https://api.github.com/users/data-handler/repos","events_url":"https://api.github.com/users/data-handler/events{/privacy}","received_events_url":"https://api.github.com/users/data-handler/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-06-01T13:31:11Z","updated_at":"2018-06-01T16:46:37Z","closed_at":null,"author_association":"NONE","body":"### Minimal repro steps\r\n\r\n1. Create Model with child \r\n\r\n```\r\npublic class CompanyAddress\r\n    {\r\n        public Guid Id { get; set; }\r\n        public Company Company { get; set; }\r\n        public string Address1 { get; set; }\r\n        public string Address2 { get; set; }\r\n        public string Address3 { get; set; }\r\n        public string Address4 { get; set; }\r\n        public string Address5 { get; set; }\r\n        public string Postcode { get; set; }\r\n    }\r\n\r\npublic class Company\r\n    {        \r\n        public Guid Id { get; set; }\r\n        public string Name { get; set; }        \r\n        public CompanyType Type { get; set; }\r\n    }\r\n```\r\n\r\n2. Create View with Parent Model\r\n\r\n```\r\n.................\r\n@model CompanyAddress\r\n\r\n<form asp-controller=\"Company\" asp-action=\"Save\" data-ajax=\"true\" data-ajax-method=\"POST\" data-ajax-success=\"onCompanySaved\" id=\"editCompanyForm\">    \r\n    <input asp-for=\"Id\" type=\"hidden\">\r\n    <input asp-for=\"Company.Id\" type=\"hidden\">        \r\n</form>\r\n```\r\n\r\n3. Create Controller Action to return PartialView with populated parent model\r\n```\r\npublic async Task<IActionResult> Edit(Guid id)\r\n        {\r\n            var model = await _companyAddressRepository.GetByIdAsync(id);\r\n            return PartialView(model);\r\n        }\r\n```\r\n\r\n4. View rendered page in browser\r\nIn my case, I am calling the Action using JQuery ajax\r\n![image](https://user-images.githubusercontent.com/7189305/40843792-09757b34-65aa-11e8-9f2e-19ca30d534a7.png)\r\n\r\n\r\n### Expected result\r\nValue for hidden input using asp-for=\"Id\" should equal Model Id\r\n\r\n### Actual result\r\nValue for hidden input using asp-for=\"Id\" equals child Id (Model.Company.Id)\r\n\r\n### Further technical details\r\n\r\ncsproj file:\r\n\r\n```\r\n<Project Sdk=\"Microsoft.NET.Sdk.Web\">\r\n\r\n  <PropertyGroup>\r\n    <TargetFramework>netcoreapp2.1</TargetFramework>\r\n  </PropertyGroup>\r\n  \r\n  <ItemGroup>\r\n    <PackageReference Include=\"BuildBundlerMinifier\" Version=\"2.8.391\" />\r\n    <PackageReference Include=\"Microsoft.AspNetCore.All\" Version=\"2.1.0\" />    \r\n  </ItemGroup>\r\n  \r\n</Project>\r\n```\r\n\r\n- I have confirmed via debug that the model passed to the view has the correct values for parent and child Id properties.\r\n- When using asp-for helper, the value for both hidden inputs equals the child Id (Company.Id)\r\n- When using the following syntax for the parent Id input, the value rendered is correct\r\n<input id=\"Id\" name=\"Id\" type=\"hidden\" value=\"@Model.Id\" />"},"comment":{"url":"https://api.github.com/repos/aspnet/Mvc/issues/comments/393940245","html_url":"https://github.com/aspnet/Mvc/issues/7850#issuecomment-393940245","issue_url":"https://api.github.com/repos/aspnet/Mvc/issues/7850","id":393940245,"node_id":"MDEyOklzc3VlQ29tbWVudDM5Mzk0MDI0NQ==","user":{"login":"mkArtakMSFT","id":34246760,"node_id":"MDQ6VXNlcjM0MjQ2NzYw","avatar_url":"https://avatars3.githubusercontent.com/u/34246760?v=4","gravatar_id":"","url":"https://api.github.com/users/mkArtakMSFT","html_url":"https://github.com/mkArtakMSFT","followers_url":"https://api.github.com/users/mkArtakMSFT/followers","following_url":"https://api.github.com/users/mkArtakMSFT/following{/other_user}","gists_url":"https://api.github.com/users/mkArtakMSFT/gists{/gist_id}","starred_url":"https://api.github.com/users/mkArtakMSFT/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mkArtakMSFT/subscriptions","organizations_url":"https://api.github.com/users/mkArtakMSFT/orgs","repos_url":"https://api.github.com/users/mkArtakMSFT/repos","events_url":"https://api.github.com/users/mkArtakMSFT/events{/privacy}","received_events_url":"https://api.github.com/users/mkArtakMSFT/received_events","type":"User","site_admin":false},"created_at":"2018-06-01T16:46:36Z","updated_at":"2018-06-01T16:46:36Z","author_association":"CONTRIBUTOR","body":"Thanks for contacting us, @data-handler.\r\n@NTaylorMullen can you please look into this? Thanks!"}}
{"actor":{"display_login":"mkArtakMSFT"}}