Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can i have a CheckBoxFor using int?

I need help to build a CheckBoxFor for getting an int value.

Something like:

@Html.CheckBoxForInt(m => m.foo.intValue)

It should be checked if intValue = 1 else not checked.

like image 913
n3tx Avatar asked Nov 22 '12 15:11

n3tx


1 Answers

Why don't you expose a bool property in your model that converts to/from the int?

Something like this:

public bool BoolValue
{
    get { return IntValue == 1; }
    set { IntValue = value ? 1 : 0;}
}

public int IntValue { get; set; }

Then you could use it to create the checkbox

@Html.CheckBoxFor(m => m.foo.BoolValue)
like image 87
Daniel J.G. Avatar answered Sep 21 '22 08:09

Daniel J.G.