{"action":"created","issue":{"url":"https://api.github.com/repos/aspnet/Mvc/issues/8111","repository_url":"https://api.github.com/repos/aspnet/Mvc","labels_url":"https://api.github.com/repos/aspnet/Mvc/issues/8111/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/Mvc/issues/8111/comments","events_url":"https://api.github.com/repos/aspnet/Mvc/issues/8111/events","html_url":"https://github.com/aspnet/Mvc/issues/8111","id":342456218,"node_id":"MDU6SXNzdWUzNDI0NTYyMTg=","number":8111,"title":"Is it possible to combine [FromRoute] and [FromBody] in ASP.NET Core?","user":{"login":"abatishchev","id":351644,"node_id":"MDQ6VXNlcjM1MTY0NA==","avatar_url":"https://avatars1.githubusercontent.com/u/351644?v=4","gravatar_id":"","url":"https://api.github.com/users/abatishchev","html_url":"https://github.com/abatishchev","followers_url":"https://api.github.com/users/abatishchev/followers","following_url":"https://api.github.com/users/abatishchev/following{/other_user}","gists_url":"https://api.github.com/users/abatishchev/gists{/gist_id}","starred_url":"https://api.github.com/users/abatishchev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/abatishchev/subscriptions","organizations_url":"https://api.github.com/users/abatishchev/orgs","repos_url":"https://api.github.com/users/abatishchev/repos","events_url":"https://api.github.com/users/abatishchev/events{/privacy}","received_events_url":"https://api.github.com/users/abatishchev/received_events","type":"User","site_admin":false},"labels":[{"id":70264664,"node_id":"MDU6TGFiZWw3MDI2NDY2NA==","url":"https://api.github.com/repos/aspnet/Mvc/labels/question","name":"question","color":"cc317c","default":true}],"state":"open","locked":false,"assignee":{"login":"dougbu","id":6431421,"node_id":"MDQ6VXNlcjY0MzE0MjE=","avatar_url":"https://avatars1.githubusercontent.com/u/6431421?v=4","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},"assignees":[{"login":"dougbu","id":6431421,"node_id":"MDQ6VXNlcjY0MzE0MjE=","avatar_url":"https://avatars1.githubusercontent.com/u/6431421?v=4","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}],"milestone":null,"comments":21,"created_at":"2018-07-18T19:13:29Z","updated_at":"2018-08-05T07:46:39Z","closed_at":null,"author_association":"NONE","body":"#### Is this a Bug or Feature request?:\r\n\r\nQuestion.\r\n\r\n#### Description of the problem:\r\n\r\nI asked this question on [Stack Overflow](https://stackoverflow.com/questions/51316269/is-it-possible-to-combine-fromroute-and-frombody-in-asp-net-core). It got a number of upvotes so people are interested. But the only one answer is very specific, not generic enough. And that's what I'm looking for.\r\n\r\nI have an action on API controller like this:\r\n\r\n```c#\r\n    [HttpPost]\r\n    public async Task<IActionResult> StartDeployment(\r\n        [FromQuery]Guid deploymentId,\r\n        [FromRoute]RequestInfo requestInfo,\r\n        [FromBody]DeploymenRequest deploymentRequest)\r\n    {\r\n    }\r\n```\r\n\r\nwhich is available by complex url (`requestInfo`) and receives HTTP POST request payload (`deploymentRequest`).\r\n\r\nIs it possible to combine `[FromRoute]` and `[FromBody]` so I would have single request model:\r\n\r\n```c#\r\n    public class UberDeploymentRequestInfo\r\n    {\r\n        [FromQuery]public Guid DeploymentId { get; set; }\r\n\r\n        [FromRoute]public RequestInfo RequestInfo { get; set; }\r\n\r\n        [FromBody]public DeploymenRequest DeploymentRequest { get; set; }\r\n    }\r\n```\r\n\r\nso I could have single validator using Fluent Validation:\r\n\r\n```c#\r\n    internal class UberDeploymentRequestInfoValidator : AbstractValidator<UberDeploymentRequestInfo>\r\n    {\r\n        public UberDeploymentRequestInfoValidator()\r\n        {\r\n            // validation rules can access both url and payload\r\n        }\r\n    }\r\n```\r\n\r\n#### Version of `Microsoft.AspNetCore.Mvc` or `Microsoft.AspNetCore.App` or `Microsoft.AspNetCore.All`:\r\n\r\n2.1.0"},"comment":{"url":"https://api.github.com/repos/aspnet/Mvc/issues/comments/410502446","html_url":"https://github.com/aspnet/Mvc/issues/8111#issuecomment-410502446","issue_url":"https://api.github.com/repos/aspnet/Mvc/issues/8111","id":410502446,"node_id":"MDEyOklzc3VlQ29tbWVudDQxMDUwMjQ0Ng==","user":{"login":"dougbu","id":6431421,"node_id":"MDQ6VXNlcjY0MzE0MjE=","avatar_url":"https://avatars1.githubusercontent.com/u/6431421?v=4","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":"2018-08-05T07:46:39Z","updated_at":"2018-08-05T07:46:39Z","author_association":"MEMBER","body":"@abatishchev you need to adjust names (really, make sure they don't change) while moving from parameters to Über-binding. You also must not change the types. The following works:\r\n``` c#\r\npublic class NestedModel\r\n{\r\n    [FromRoute]\r\n    public Guid DeploymentId { get; set; }\r\n\r\n    // This is not a GUID\r\n    [FromQuery(Name = \"api-version\")]\r\n    public string ApiVersion { get; set; }\r\n\r\n    [FromRoute(Name = \"\")]\r\n    public ExtensionInfo ExtensionInfo { get; set; }\r\n\r\n    // Body shape remains unchanged\r\n    [BindProperty(Name = \"\")]\r\n    [FromBody]\r\n    public SimpleModel Properties { get; set; }\r\n}\r\n```\r\nor replace `ExtensionInfo` above with\r\n``` c#\r\n    [FromRoute]\r\n    public string StepName { get; set; }\r\n```\r\n\r\nWith the above and the `options.SuppressInferBindingSourcesForParameters = true` in place, you can add `[ApiController]` back. Further, you don't need `options.SuppressInferBindingSourcesForParameters = true` when using either `[FromMultiSource]` or `[FromModel]`.\r\n\r\nOne more alternative to the attributes or disabling `BindingSource` inference entirely is in `Startup.ConfigureServices(...)`:\r\n``` c#\r\nservices\r\n    .AddMvc(options => options.ModelMetadataDetailsProviders.Add(new BindingSourceMetadataProvider(typeof(NestedModel), BindingSource.ModelBinding)))\r\n    .SetCompatibilityVersion(CompatibilityVersion.Version_2_1);\r\n```"}}
{"actor":{"display_login":"dougbu"}}