Asp.net-mvc – Razor how to create a CheckBox and make it READONLY

asp.net-mvcasp.net-mvc-3razor

I'm using MVC 3 and Razor

At the moment I'm using

@model MyProject.ViewModels.MyViewModel

    @foreach (var item in Model.MyProperty)
{  
    <tr>
        <td>
            @Html.ActionLink("Edit", "Edit", new { id = item.AdvSlotId }) |
            @Html.ActionLink("Details", "Details", new { id = item.AdvSlotId }) |
            @Html.ActionLink("Delete", "Delete", new { id = item.AdvSlotId })
        </td>
        <td>
            @item.AdvSlotId
        </td>
        <td>
            @item.Name
        </td>
        <td>
            @item.Description
        </td>
        <td>
             @Html.CheckBox(item.IsPublished, new { @disabled = "disabled" })
        </td>
        <td>
            @item.Notes
        </td>
    </tr>    
}

The VIEW MODEL:

namespace MyProject.ViewModels
{
    public class MyViewModel
    {
        public MyViewModel(List<AdvSlot> advSlots)
        {
            MyProperty= advSlots;
        }

        public List<AdvSlot> MyProperty { get; set; }

    }
}

To display a Check Box for a property in my Model. As I'm doing is wrong so I can only display a text like TRUE.

Could you please tell me how to create the CheckBox with Razor? I would also need have it as READONLY.

Thanks for your help.

Best Answer

Should be something like this:

@Html.CheckBoxFor(m => m.IsPublished, new { @disabled = "disabled" })

UPDATE:

Assuming that your class AdvSlot contains a property IsPublished you can write in your loop:

<td>
    @Html.CheckBox(item.AdvSlotId + "_IsPublished", item.IsPublished, new { @disabled = "disabled" });
</td>