我在访问使用 Guid 参数生成 .ToList() 的服务时遇到了一些问题
public IList<Info> GetBusinessLocations(Guid businessId)
{
using (var db = new DealerContext())
{
return GetDealerDetails(
db.Details
.Join(db.BusinessLocations,
x => x.BusinessId,
y => y.BusinessId, (x, y) => x)
.Where(d => d.BusinessId == businessId), db)
.ToList();
}
}
我尝试使用 guid 作为参数编写 ActionResult,但我继续收到错误消息,即“参数字典包含参数 'businessId' 的空条目”
public ActionResult Create(Guid businessId)
{
ViewBag.Locations = new SelectList(ServiceBus.GetBusinessLocations(businessId), "BusinessId", "LocationName");
return View(IdGenerator());
}
private static Data.Models.Business IdGenerator()
{
var model = new Models.Business
{
BusinessId = Guid.NewGuid()
};
return (model);
}
在我看来,我只是将下拉列表称为
@Html.DropDownListFor(m =>m.BusinessId, (IEnumerable<SelectListItem>)ViewBag.Locations,"Select your Businesses Location")
如果有人能提供一些见解,我将不胜感激。我很难在 SO 上找到类似的场景。