Let's say I have a most basic controller
public class HomeController : Controller
{
public ActionResult Index(string id, string language)
{
return View();
}
}
Which takes in 2 parameters. However there is one requirement that the client which calls the action method should pass id
value from URL but language
value from http header. It means the url should be /Home/Index/12345
and meanwhile the calling client will set a Http Header value language : en
.
How shall I set the routing in MVC5 or MVC6 to achieve the requirement?
Please don't provide samples from Web Api.
Thanks
FromHeaderAttribute
? Try adding it to the language parameter as inpublic ActionResult Index(string id, [FromHeader] string language)
– Daniel J.G.