The second parameter value for the action method is always null. In the uri the query string contains values for both status and type. But I can get value only for the status. The type parameter is always null.
I've tried attribute routing as answered in this question. https://stackoverflow.com/a/22962461/8155033
I added [Route("Vehicles")] [Route("Vehicles/{status}/{type}")] attribute routes as mentioned in that answer. It matches with https://localhost:44355/Vehicles/8481aaed-13f8-4eee-921b-20853ab9ddf0/c07f4dd0-44d2-4c82-b174-76849d010c95%2F
VehiclesController
public async Task<IActionResult> Index(Guid? status, Guid? type )
{
var applicationDbContext = _context.Vehicles.Where(v=> v.VehicleStatusId == status && v.VehicleTypeId == type).Include(v => v.VehicleStatus).Include(v => v.VehicleType);
return View(await applicationDbContext.ToListAsync());
}
I want to get values for parameters using this. https://localhost:44355/Vehicles?status=8481aaed-13f8-4eee-921b-20853ab9ddf0&type=c07f4dd0-44d2-4c82-b174-76849d010c95%2F
It gets the value for status, but type is always null.
When I press the submit button I get the above query string.
<div>
<form name="searchbox">
<div class="form-group">
<div class="form-group">
@{
var vStatuses = ViewBag.vStatuses as ICollection<VehicleStatus>;
foreach (var vStatus in vStatuses)
{
<input type="radio" name="status" value=@vStatus.Id />
@vStatus.Label
}
}
</div>
<div class="form-group">
@{
var vTypes = ViewBag.vTypes as ICollection<VehicleType>;
foreach (var vType in vTypes)
{
<input type="radio" name="type" value=@vType.Id/>
@vType.Label
}
}
</div>
</div>
<input class="btn" type="submit" />
</form>
</div>