开发者

How can I make my own check box in MVC?

开发者 https://www.devze.com 2023-03-14 01:03 出处:网络
I would love to use the: Html.EditorFor(model => @Data.Test.Correct) To create a checkbox. However the source of my data is different from the data that needs to be updated. I know this may sou

I would love to use the:

Html.EditorFor(model => @Data.Test.Correct)

To create a checkbox.

However the source of my data is different from the data that needs to be updated. I know this may sound confusing but 开发者_StackOverflow社区I get my data from a LINQ select query and then need to update in a different place.

The only way around this seems for me to hand code the HTML for the checkbox. But can someone give me an example of how I do this. For example, how can I code in the setting of checked=true?


You may write HTML codes like below to create a selected or unselected checkbox

<input type="checkbox" name="option1" value="1" checked="checked" />
<input type="checkbox" name="option2" value="2" />

But you will need to write additional code manually to determine which checkbox should be selected, if your checkbox is dynamic generated or being filled in with stored data.

0

精彩评论

暂无评论...
验证码 换一张
取 消