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.
Unfortunately, activation email could not send to your email. Please try again.

How to disable checkbox in helper

Thread ID:

Created:

Updated:

Platform:

Replies:

126135 Sep 26,2016 01:02 PM Sep 27,2016 08:15 AM ASP.NET MVC 1
loading
Tags: Checkbox
Tom Frajer
Asked On September 26, 2016 01:02 PM

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);
        }

    }
}

Deepa Loganathan [Syncfusion]
Replied On September 27, 2016 08:15 AM

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.   


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;