We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

How to disable checkbox in helper

Hi,
I have my own CheckBoxFor implementation (I need strongy typed checkbox that you do not provide). My problem is, that Im not able to disable this checkbox. Here is the code of the helper. I highlighted part, where Im adding your class to make checkboxes look like syncfusion checkboxes. When I comment-out this highlighted line, checkbox is not styled properly, but disabling works. How can I achieve syncfusion styling and ability to control disable property of checkbox?

using System;
using System.Linq.Expressions;
using System.Web.Mvc;
using System.Web.Mvc.Html;
using System.Web.Routing;
using CarDat.Service;

namespace CarDat.Helpers
{
    public static class CheckBoxExtensions
    {

        public static MvcHtmlString LabeledCheckBoxFor<TModel>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, bool>> expression, string label)
        {
            
            // Set class attribute for css styling
            var attributes = new RouteValueDictionary();
            attributes.Add("class", "check_box");

            // Get field name
            var body = expression.Body as MemberExpression;
            var fieldName = body.Member.Name;

            // Initialize new service for retrieving user rights
            var permissionService = new PermissionService();

            // Get field read permissions for current user role
            var canRead = permissionService.HasFieldReadPermission(fieldName);

            // Get field read permissions for current user role
            var canEdit = permissionService.HasFieldWritePermission(fieldName);

            // Render HTML code for label and input field
            var html = "";
            if (canRead || canEdit) {
                if (!canEdit) {
                    attributes.Add("disabled", "disabled");
                }
                html = htmlHelper.Label(label).ToString();
                html += "<br />";
                html += InputExtensions.CheckBoxFor(htmlHelper, expression, attributes).ToString();
           }

            return new MvcHtmlString(html);
        }

    }
}

1 Reply

DL Deepa Loganathan Syncfusion Team September 27, 2016 12:15 PM UTC

Hi Tom,    
 
Sorry for the inconvenience caused. We are able to reproduce the reported issue on our end and logged a bug report to fix this. 
 
Also, we have created a new support incident under your account to track the status of this issue.  
 
Please log on to our support website to check for further updates. 
https://www.syncfusion.com/account/login?ReturnUrl=/support/directtrac/incidents                                                     
Please let us know if you have any further queries.   
 
Regards,    
Deepa Loganathan.   


Loader.
Live Chat Icon For mobile
Up arrow icon