0

i got a checkbox in my view and i want to set that as checked from mvc controller. Here is my checkbox

<td>
<input type="checkbox" name="filtroReperibilita" id="filtroReperibilita" style="height:25px; width:25px; margin-left:5px; margin-top:5px;" />
</td>

I have the value that i want to set to it in session. can you help me?

1 Answer 1

2

Solution 1, If using ASP-Core:

use asp-for Tag Helper and set property true in the controller.

public class MyModel
{
    public bool FiltroReperibilita { get; set; }
}

<td>
   <input class="form-check-input" asp-for="FiltroReperibilita"/> @Html.DisplayNameFor(model => model.FiltroReperibilita)
</td>

For more information about Tag Helpers see Microsoft document.

Solution 2:

Consider the previous model and use this code:

<input type="checkbox" name="filtroReperibilita" id="filtroReperibilita" class="form-check-input" @(Model.FiltroReperibilita ? "checked" : string.Empty) />
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.