How to use DropDownList binded to model inside WebGrid razor asp net mvc 4?

后端 未结 1 1567
孤街浪徒
孤街浪徒 2020-12-21 23:09

After hours of searching in google and trying different syntaxis I decided to post this. The problem is I can\'t get the right way to use a DropDownList inside a webgrid. Co

相关标签:
1条回答
  • 2020-12-21 23:30

    Try the following format:

    grid.Column(
        "TodosLosRoles", 
        "Roles", 
        format: item => Html.DropDownList(((int)item.UserId).ToString(), Model[0].TodosLosRoles)
    )
    

    It's kinda crap, but WebGrid is crap in general. It relies on weak dynamic typing, you can forget about strong typing and proper view model if you rely on this component. Prepare to cast as hell and for potential runtime errors if you are not extremely careful about the types you are passing.

    0 讨论(0)
提交回复
热议问题