ASP.NET MVC3 WebGrid format: parameter

后端 未结 3 939
北海茫月
北海茫月 2021-01-04 09:23

I am trying to use the new WebGrid in ASP.NET MVC3 and one of the columns I want to display set of link icons that performs various actions (Edit, View, Delete)... For this

3条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-04 09:51

    I got it :) .... The issue appears to be in the way C# handles dynamic objects...Lots of users are having a blast with this...

    The fix was as simple as casting a correct type on the parameter to my extension helper... So this works:

    grid.Column(header: "", format: @@Html.ActionLinkIconForEditAction("Customer", (int)item.Id)
    

    The other trick is to use "built" in "item" object and not provide your own..So, for example, this does not work:

    grid.Column(header: "", format: (customer) =>  @@Html.ActionLinkIconForEditAction("Customer", (int)customer.Id)
    

    Lots of reading, tweaking, learning... Hopefully, next version will have something a lot easier to use when you need to add content to columns that are not coming directly from the model...

    Regards Z...

提交回复
热议问题