Search code examples
c#asp.net-mvchtml-helper

How do I use checkboxfor htmlhelper with a bool property of class that is a property of my viewmodel


I thinks my question will be best understood with the example below.

public Class1 
{
    public bool SomeProperty1 {get;set;}
    public string SomeProperty2 {get;set;}
}

public Class2
{
    //bool property in which i want to use the checkboxfor
    public List<Class1> SomeProperty3 {get;set;} 

    public string SomeProperty4 {get;set;}
}

@model Class2

@Html.Textboxfor(SomeProperty4)...
.
.
.
@foreach(var x in SomeProperty3)
{
    <td>Html.Checkboxfor(model=>x.SomeProperty1...) </td>
    //How?
}

I also cant figure out how to add a disabled property to the html element.


Solution

  • you can using html attributes as below.

    Html.Checkboxfor(model=>x.SomeProperty1,new {@disabled="diasbled"})