Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding style to Editor For

I'm trying to apply a Style to the Editor for an element, but I can't make it work; what am I doing wrong?

@Html.EditorFor(model => model.ClienteNuevo)
@Html.ValidationMessageFor(model => model.ClienteNuevo,"" ,new Dictionary<string,     string> { { "style", "width:500px" } })
like image 245
Jorge Avatar asked Oct 13 '11 19:10

Jorge


People also ask

What is editor style?

Editor Style is a theme feature introduced with Version 3.0. This feature allows you to link a custom stylesheet file to the TinyMCE editor within the post edit screen.

How do I add styles to wysiwyg editor?

Add new styles to the "Styles" dropdown in the What You See Is What You Get (WYSIWYG) toolbar, which are then also used for the "Class" dropdown available when inserting links, images, and media on pages. These styles can be block-level or span-level.

How do you style Gutenberg editor?

Gutenberg editor doesn't have its own styling options. The only way to change the appearance of the page is to change the template of the whole website. JetStyleManager is a Gutenberg block styles plugin that adds the design customization block for JetPlugins that work with Gutenberg.


2 Answers

Since MVC 5.1, you can pass in custom attributes with using the htmlAttributes as a key:

@Html.EditorFor(model => model.ClienteNuevo, 
    new { htmlAttributes = new { @class = "form-control" } })

In older MVC versions there is no way to add html attributes with the EditorFor method.
You should create a custom editor template or use Html.TextboxFor istead of EditorFor. You should check these topics topic1, topic2.

like image 129
nemesv Avatar answered Oct 17 '22 06:10

nemesv


You can create own css class and appendd it to your editor:

@Html.EditorFor(model => model.Name, new { htmlAttributes = new { @class = "custom-editor" } })
@Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" })
like image 37
1_bug Avatar answered Oct 17 '22 08:10

1_bug