0

デフォルトで選択された値http://www.mikesdotnetting.com/Article/202/Inline-Editing-With-The-WebGridでドロップダウンリストを使用して WebGrid を開発しようとしています。

// Controller 内のコード (複数のデータ セットを取得します):

ViewBag.material_codes = new SelectList(db.Master_Material, "material_code", "material_code");

//View(WebGrid) のコード:

grid.Column("material_code", MenuItemModel.translateMenuItem("MaterialCode"), format: 
                            @<text>
                                 @Html.DropDownList("material_code", (SelectList)ViewBag.material_code, item.material_code)
                            </text>),

ただし、次のエラーが表示されます。

 Error  1   'System.Web.Mvc.HtmlHelper<IMv3.ViewModels.RMReceivingViewModels>' has no applicable method named 'DropDownList' but appears to have an extension method by that name. Extension methods cannot be dynamically dispatched. Consider casting the dynamic arguments or calling the extension method without the extension method syntax.  

「item.material_code」が原因だと思いますが、何かアイデアはありますか?

4

1 に答える 1

0

拡張メソッド ( などDropDownList) に動的パラメーターを含めることはできません。item.material_codeしたがって、をその基になる型にキャストする必要があります。

@Html.DropDownList(
    "material_code", 
    (SelectList)ViewBag.material_code, 
    (string)item.material_code
)

ここでは文字列にキャストしますが、基になる型が異なる場合はコードを調整する必要があります。

于 2013-03-05T09:50:32.103 に答える