操作方法的第二个参数值始终为null。在uri中,查询字符串包含状态和类型的值。但是我只能从地位上获得价值。 type参数始终为null。
我已经尝试过按此问题回答的属性路由。 https://stackoverflow.com/a/22962461/8155033
我添加了[Route(“ Vehicles”)] [Route(“ Vehicles / {status} / {type}”)]属性路由,如该答案所述。它与 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());
}
它获取状态值,但类型始终为空。
当我按下提交按钮时,我得到了上面的查询字符串。
<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>