Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8010801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:50:53+00:00 2026-06-04T18:50:53+00:00

I use this: <input type=checkbox value=@item.Id checked=@(item.HasAccess ? checked : )/> This worked correctly:

  • 0

I use this:

<input type="checkbox" value="@item.Id" checked="@(item.HasAccess ? "checked" : "")"/>

This worked correctly: I mean when HasAccess is true then checked="checked" and when
HasAccess is false then checked="" but always the checkboxs checked, how can I use ternary operator and handle checked attribute correctly?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T18:50:54+00:00Added an answer on June 4, 2026 at 6:50 pm

    Unfortunately, in razor V1, you must do it this way:

    <input type="checkbox" value="@item.Id" @(item.HasAccess ? "checked=\"checked\"" : "") />
    

    This is because in the HTML world, the mere presence of the attribute at all, regardless of the value, tells the browser to check the box.

    In Razor V2, this will be less of a problem. See the conditional attributes section of the article below:

    http://vibrantcode.com/blog/2012/4/10/whats-new-in-razor-v2.html/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use this code to determine checkbox width and height: var chk = $('input[type=checkbox]:first');
i have a form with checkboxes like this: <input type=checkbox name=type[] value=1 />Fast Food<br>
i'm new to jquery, so forgive me my misunderstandings. i use this code: $(.redbox).delegate(input[type=checkbox],
i have some html snip like this <input type=checkbox name=color value=red/>red <input type=checkbox name=color
I have this code: <INPUT type=button value=Pre-Requisites onClick=window.open('pre_requisites.php','pre-requisites','width=670px,height=470px,left=0px,top=100px,screenX=0,screenY=100')> It is use to open a
I have the folowing inptuts! <input type=checkbox value=1 /> <input type=checkbox value=2 /> <input
I have a codeigniter form that contains two checkboxes: <input type=checkbox checked=checked id=box1 name=box1
I have a list of checkboxes for timezones, something like this: <input type=checkbox class=TimeZoneCheckbox
<label for=q11><input type=checkbox class=styled value= Good name=q11[] id=q11_1>Good</label> <label for=q11><input type=checkbox class=styled value= Poor
following structure: <label class=selectit> <input value=3 type=checkbox name=tax_input[event_type][] id=in-event_type-3> Workshops </label> I can easily

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.