0

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' の null エントリが含まれています」というエラーが引き続き発生します。

 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で同様のシナリオを見つけるのに苦労しています。

4

1 に答える 1

0

このコードを大幅に変更してしまったので、修正してこの質問を閉じます。うまくいけば、その方法は他の誰かを助けることができます.

サービスクエリ

public IList<DealerInfo> GetBusinessLocations(Guid? locationId)
         {
        using (var db = new DealerContext())
             {
            var query = db.DealerDetails
                .Join(db.DealerValidations,
                    d=>new {bizId=d.BusinessId,lId=d.LocationId},
                    dv=>new {bizId=dv.BusinessID,lId= dv.LocationID},
                    (d,dv)=>d);

            if (locationId.HasValue)
                query = query.Where(d => d.LocationId == locationId.Value);

            return GetDealerDetails(query)
                .OrderBy(d =>d.DealerName)
                .ToList();
        }
    }

コントローラ アクション

    public ActionResult GetLocations(Guid? id)
    {
        IList<DealerInfo> locations;

        locations = Service.GetBusinessLocations(id);


        ViewData["LocationId"] = new SelectList(locations, "LocationId", "DealerName", "(Select)");

        return PartialView("_DealerDropDown");
    }

部分図

<div class="editor-field" id="locationdropdown">
    @Html.DropDownList("LocationId", ViewData["LocationId"] as SelectList, "(Select)", new { onchange = "onLocationSelected()", id="querydrop" })

</div>

これは私の特定の問題に非常に固有のものであることはわかっていますが、同様のシナリオの誰かがこれを役に立つと思うかもしれません.

于 2013-08-08T16:47:55.923 に答える