RadiobuttonFor in Mvc Razor syntax

后端 未结 1 1820
逝去的感伤
逝去的感伤 2021-02-07 18:27

I have three radio buttons and my field value type is integer like Maintenance for 3, Active for 1 and Inactive for 2.

@Html.RadioButtonFor(mod         


        
1条回答
  •  忘了有多久
    2021-02-07 18:50

    The way I create radiobuttons is as follows:

    @Html.RadioButtonFor(model => model.StatusId,3,new { id = "rbMaintenance" })
    @Html.Label("rbMaintenance","Maintenance")
    @Html.RadioButtonFor(model => model.StatusId,2,new { id = "rbInactive" })
    @Html.Label("rbInactive","Inactive")
    @Html.RadioButtonFor(model => model.StatusId,1,new { id = "rbActive" })
    @Html.Label("rbActive","Active")
    

    The difference to your code really is that as your StatusId type is Int then you should enter the value in the RadioButtonFor as an integer e.g. 3 for Maintenance rather than '3'.

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