转换为CheckBoxFor HTMLHelper

时间:2014-06-12 18:59:52

标签: asp.net-mvc razor casting

我正在编写一个editorTemplate,其目标是获取一个值,显示其标签,然后选择适当的控件放在它旁边。

@model object

if (Model is bool)
        {
            @Html.CheckBoxFor(m => m.? , new { @class = @ViewData["class"], style = @ViewData["style"], id = @ViewData["id"] })
        }

我想拍摄该模型,并将其作为一个bool粘贴在该复选框中。

m => (bool)m不起作用,m => m,也不是" m => m.As<>"
CheckboxFor不接受普通对象,如果我进行转换,我会得到以下内容

Additional information: Templates can be used only with field access, 
property access, single-dimension array index, or 
single-parameter custom indexer expressions.

这里有什么最好的方法,一个新助手?其他

1 个答案:

答案 0 :(得分:0)

   <input type="checkbox" name="nameofproperty" checked='@(Model.nameofproperty == 1 ? true : false)' id="yourid"   value="1" />

在检查中你可以施放你的物体。