Change URL of / controller? id = 1 to / controller / 1

1

In my view I have two buttons that pass parameters via GET to the index of my controller, the problem is that the URL does not stay with the traditional? id = 1 and I wanted to make it look like this: / controller / 1

View:

@using (Html.BeginForm(FormMethod.Get))
        {
            <button type="submit" class="btn btn-primary" value="1" name="id">sites1</button>
            <button type="submit" class="btn btn-primary" value="2" name="id">sites2</button><br />

        }

Controller:

 public async Task<IActionResult> Index(int? id)
    {
        var listaDeSites = await _listaService.ListaDeSitesAsync(id);
        return View(listaDeSites);
    }
    
asked by anonymous 27.09.2018 / 19:59

1 answer

2

You could put the following annotation:

[HttpGet("{id}")]

It looks like this:

[HttpGet("{id}")]
public async Task<IActionResult> Index(int? id)
{
    var listaDeSites = await _listaService.ListaDeSitesAsync(id);
    return View(listaDeSites);
}
    
28.09.2018 / 15:27