None
None

Reputation: 5670

Unable to set HTML custom attribute value using Razor

I have a checkbox like this

<input type="checkbox"  doublecheck="@item.isReusable">

and the item.isReusable is a bool field. Value inside it is either True or false. But when the HTML gets rendered I always get the result like this

<input type="checkbox" doublecheck="doublecheck">

What can be the reason I am unable to set True/False as the value of my custom attribute doublecheck ? And how can I solve this issue?

Upvotes: 0

Views: 53

Answers (1)

Yiyi You
Yiyi You

Reputation: 18159

You can try to use HtmlHelper,here is a demo:

Model:

public class TestModel
    {
        public bool isReusable { get; set; } = true;
        
    }

View:

@Html.CheckBox("checkbox1", new { doublecheck = Model.isReusable ,value=false})

Generated Html: enter image description here

Upvotes: 0

Related Questions