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

  • SEARCH
  • Home
  • 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 7016885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:50:36+00:00 2026-05-27T22:50:36+00:00

I’m using MVC3 and I would like to make my views be fully integrated

  • 0

I’m using MVC3 and I would like to make my views be fully integrated with the jQueryUI themes. This means that for standard @Html.EditorFor fields, I would like their css classes to implement the jQueryUI theme that I have selected, and if I switch themes, that my standard MVC3 inputs change accordingly, even if not decorated with the jQueryUI enhancements?

By default, when I call @Html.EditorFor(x => Model.FirstName), the output is as follows:

<input class="text-box single-line" data-val="true" data-val-length="The First Name field must be between 3 and 50 characters in length" data-val-length-max="50" data-val-length-min="3" data-val-required="The FirstName field is required." id="FirstName" name="FirstName" type="text" value="John" />

This is nice and clean, because I have all the validation attributes included. However, if I try to call @Html.EditorFor(x => Model.FirstName, new { @class = "ui-widget ui-state-default ui-widget-content" }) to apply the jQueryUI styling, the CSS classes aren’t applied to the input field (they stay “text-box single-line”).

I did find that if I change @Html.EditorFor() to @Html.ListBoxFor() and include the “new { @class = “…” }” with my selected css classes, it renders with the proper jQueryUI classes, but I really like the flexibility of EditorFor to use with any type of input. However, even when using just TextBoxFor, I don’t like having to include the jQueryUI classes each time.

To try to overcome this, I tried creating a shared EditorTemplate that derives from System.String and manually putting in the css classes, which worked, but then I loose all the automatic functionality for validation attributes and it seems “hokey”. There seems like there has got to be an easier way to automatically apply custom CSS globally to EditorFor helpers.

So my questions are:

  1. How can I tell EditorFor to use custom CSS classes?
  2. How can I override the EditorFor (or at a minimum the TextBoxFor) to globally apply CSS classes so I don’t have to keep repeating them?
  3. As a bonus, are there any references out there as to what the jQueryUI classes are used for (e.g. when should I apply ui-state-default vs. ui-widget-content) so that all my standard MVC3 inputs look like inputs decorated with jQueryUI enhancements?
  • 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-05-27T22:50:36+00:00Added an answer on May 27, 2026 at 10:50 pm

    1) You cannot use the existing EditorFor() for specifying addtional html parameters. The parameter you are using in your example is for additional view data and not html attributes. The EditorFor() will create its own HTML attributes.

    Alternatively, you can use TextBoxFor() instead and use the htmlAttributes parameter:

    @Html.TextBoxFor(m => m.UserName, new { @class = "ui-widget ui-state-default ui-widget-content" })
    

    2) The EditorFor() template can be overriden using an Editor Template. This link demonstrates how.

    Basically, to create an EditorTemplate you will need to create a folder named

    EditorTemplates

    in the Views folder. The name of the folder must be exact and the location of the folder is relevant. If the EditorTemplates folder is placed within the Views/Account folder (if this existed say) for example then the template will only be available to the relevant account views. If you place it within the Shared folder then it will be available to all views.

    In the EditorTemplates folder you should create a partial view that is named after the data type that is to be processed. For example, I am assuming that you will only want strings processed with EditorFor so I have named it String.cshtml.

    Then in the partial view I have defined the following:

    @inherits System.Web.Mvc.WebViewPage<string>
    
    @Html.TextBoxFor(m => m, new { @class = "ui-widget ui-state-default ui-widget-content" })
    

    And thats it. Anywhere that the EditorFor now processes a string you should get something like:

    <input class="ui-widget ui-state-default ui-widget-content" data-val="true" data-val-required="The User name field is required." id="UserName" name="UserName" type="text" value="" />
    

    3) Ideally, you should only really ask a single question in a Stack Overflow question and a simple google search should be able to answer this. However, here are the definitions of ui-state-default and ui-widget-content:

    .ui-state-default: Class to be applied to clickable button-like
    elements. Applies “clickable default” container styles to an element
    and its child text, links, and icons.

    .ui-widget-content: Class to be applied to content containers. Applies
    content container styles to an element and its child text, links, and
    icons. (can be applied to parent or sibling of header)

    Hope this helps.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am reading a book about Javascript and jQuery and using one of the
this is what i have right now Drawing an RSS feed into the php,

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.