Andrea Aloi
Andrea Aloi

Reputation: 991

DevExpress MVC LabelFor - set css class

I have a simple label rendered with the LabelFor MVC HtmlHelper, and I can't seem to find a way to attach a css class to it, it's driving me up the wall.

<div>
@Html.DevExpress().LabelFor(m => m.Total, settings => {
    settings.Name = "Total";
    settings.Width = Unit.Percentage(100);
}).Bind(Model.Total).GetHtml()
</div>

According to the documentation it would seem sufficient to add a third parameter specifying html attributes, so naturally I attempted:

<div>
@Html.DevExpress().LabelFor(m => m.Total, settings => {
    settings.Name = "Total";
    settings.Width = Unit.Percentage(100);
}, new { @class = "myLabel" }).Bind(Model.Total).GetHtml()
</div>

but Visual Studio complains this is an invalid overload of the LabelFor() method.
Any clues? Thanks.

EDIT: I've look around and according to this question it seems there are no built-in overloads of LabelFor() which accept an object specifying html attributes (the OP's question regarded the id attribute); and if I right-click on the method and jump to its definition I am presented with this, which would also confirm the fact that LabelFor() does not accept the object parameter:

#region Assembly DevExpress.Web.Mvc5.v14.1.dll, v14.1.4.0
// C:\Program Files (x86)\DevExpress 14.1\Components\Bin\Framework\DevExpress.Web.Mvc5.v14.1.dll
#endregion

using DevExpress.Web.ASPxClasses;
using DevExpress.Web.ASPxEditors;
using System;
using System.Web.Mvc;

namespace DevExpress.Web.Mvc
{
    public class LabelExtension : EditorExtension
    {
        public LabelExtension(LabelSettings settings);
        public LabelExtension(LabelSettings settings, ViewContext viewContext);

        protected internal MVCxLabel Control { get; }
        protected override EditPropertiesBase Properties { get; }
        protected internal LabelSettings Settings { get; }

        protected override void AssignInitialProperties();
        protected override ASPxWebControl CreateControl();
        protected override bool IsSimpleIDsRenderModeSupported();
    }
}

But Todd's comment to the first answer, along with the MSDN docs I linked above, would suggest otherwise.
Which is it?

Upvotes: 0

Views: 1858

Answers (1)

G&#252;rkan Arslan
G&#252;rkan Arslan

Reputation: 98

I think you are looking for:

    settings.ControlStyle.CssClass = (CssClassName);

it worked for me. I Hope i will work for you

Upvotes: 3

Related Questions