0

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.

Jc Balantakbo
  • 115
  • 1
  • 8
  • So what exactly is the problem? You are already using `Checkboxfor`, so is your question only aimed at figuring out how to make it disabled? – Grizzly Aug 01 '17 at 14:56
  • First you cannot use a `foreach` loop to generate form controls for a collection (refer [this answer](http://stackoverflow.com/questions/30094047/html-table-to-ado-net-datatable/30094943#30094943)). But even if your generate your form controls correctly, adding the disabled attribute means that the value of `SomeProperty1` will always be `false` when you submit your form (since disabled controls do not submit a value). Why are you wanting a disabled checkbox? –  Aug 01 '17 at 22:59

1 Answers1

2

you can using html attributes as below.

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

Grizzly
  • 5,873
  • 8
  • 56
  • 109
Komal
  • 71
  • 5