You need to define where this value comes from.
In case of a GET request, it may come from the route:
[HttpGet("{hosts}"), ActionName("Search")]
public async Task<IActionResult> Search([FromRoute] string hosts)
{
...
}
In this case the call would be: http://url-base/Search/valor-hosts
.
Or you can receive it via querystring
[HttpGet, ActionName("Search")]
public async Task<IActionResult> Search([FromQuery] string hosts)
{
...
}
The call would be: http://url-base/Search?hosts=valor-hosts
.
It is also possible to receive a value of a header, but I doubt it’s useful now.
According to his comment, the same problem is in the assembly of view. Here’s an example of how to do.
@{
var querystringValues = new Dictionary<string, string>
{
{ "hosts", "teste-teste" }
};
}
<a asp-controller="Histories" asp-action="Search"
asp-all-route-data="querystringValues">Clique aqui</a>
Hello, he keeps returning Null, strange..
– Matheusls
@Matheusls How are you calling the route?
– Jéf Bueno
<a Asp-controller="Histories" Asp-action="Search" Asp-route-id="@item. Host" >, that’s what I call in the View.
– Matheusls
It makes no sense to use
asp-route-id
to send a querystring. Take a look in the documentation– Jéf Bueno
@Matheusls Anyway, this is not a problem in the controller but in the view. You should have specified this in the question (along with the view code).
– Jéf Bueno
It worked, thanks for the help and sorry for the lack of attention =p
– Matheusls