Thursday, 11 July 2013

Checkboxes Beside Labels in ASP.Net MVC4

This had me stumped for a while, so here’s what you need to do:

Inside your form,

@Html.CheckBoxFor(m => m.XX)
@Html.LabelFor(m => m.XX, new {@class="checkbox"})

This is for a boolean XX in the model, marked with the appropriate attributes to get the label text. The important thing is the class attribute for the label, because that applies the style defined in the default css:

label.checkbox { display: inline;}

To make it appear on the same line as the checkbox itself.

1 comment:

  1. Great Article
    Cyber Security Projects

    projects for cse

    Networking Security Projects

    JavaScript Training in Chennai

    JavaScript Training in Chennai

    The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training