mardi 3 juillet 2018

Convert html to checkbox razor view

I have the following checkbox:

<input type="checkbox" id="seaMode" name="transportMode" value="Origin Service" />
<label for="seaMode" data-label="Sea">Sea</label>

However I am using razor view for that binding the view to the model:

@foreach (var val in Model.TransportList)
{
    @Html.Label(val.Value, htmlAttributes: new { @for = label })
    <i class=@val.Image></i>
    @Html.CheckBox(label, false, new { value = @val.Text, name = "transportMode" })
}

Right now, it is returning it as below:

<label for="SEAMode">SEA</label>
<i class="icon-sea"></i>
<input id="SEAMode" name="SEAMode" type="checkbox" value="1">
<input name="SEAMode" type="hidden" value="false">

Any one good with html can please help me to add the correct class and attribute so as to render the html as the 1st one?

For info, val.Value has SEA and val.Text = 1 and so on.




Aucun commentaire:

Enregistrer un commentaire