Can I use a named argument when calling a method with a lambda expression for a parameter?

I play with named arguments and optional parameters in C # 4.

In particular, I'm trying to use named arguments when calling HtmlHelpers in ASP.NET MVC, for example ...

@Html.DropDownList(name: "ItemGroup", 
                   selectList: Model.ItemGroupList, 
                   htmlAttributes: new { style="width:300px;" })

But what if I want to use strongly typed helpers that take a lambda expression as their first parameter instead of a string value?

@Html.DropDownListFor(expression: m => m.ItemGroup, 
                      selectList: Model.ItemGroupList, 
                      htmlAttributes: new { style = "width:300px;" })

The above code indicates an error in the lines "type arguments ... cannot be taken out of use".

By the way, this works fine ...

@Html.DropDownListFor(m => m.ItemGroup, 
                      selectList: Model.ItemGroupList, 
                      htmlAttributes: new { style = "width:300px;" })

, , - , -, , . , , - . , .

+3
1

"... ", , , selectList, SelectList. :

Html.DropDownListFor(x => x.ReferralAgencyId,
                selectList: new SelectList(Model.ReferralAgencies, "ReferralAgencyId", "Description", Model.ReferralAgencyId))

, :

Html.DropDownListFor(expression: x => x.ReferralAgencyId,
                selectList: new SelectList(Model.ReferralAgencies, "ReferralAgencyId", "Description", Model.ReferralAgencyId))

, ":" , . , , Url.Action(actionName: "MyPage", _: "MyController" ) . , -.

0

All Articles