I have the following two types of multiline textareas in my views:
<textarea cols="100" rows="15" class="full-width" id="dialogText"
name="Text">@Model.Text</textarea>
<textarea cols="100" rows="10" class="full-width" id="dialogText"
name="Text">@Model.Text</textarea>
I would like to take advantage of custom editor templates, but keep the ability to specify attributes differently (e.g. the rows
are different between the two above).
Is it possible for me to declare and use two different kinds of templates for the same field? If so then how should I declare the template and how do I specify the different templates to use?
Also how can I declare the different cols and rows. Can I use cols,rows or should I specify height and width in CSS
such as width=500px, height=600px
or 400px
?
You could override the default editor template (
~/Views/Shared/EditorTemplates/MultilineText.cshtml
):and then assuming you have defined a view model:
inside the main view you could do this:
which will render the expected output:
Also you could enhance the editor template so that you don't need to specify the @class attribute at every EditorFor call like this:
and now you could:
Oh and don't forget that ids must be unique in HTML so this
id = "dialogText"
should obviously be different for the second textarea.you can create an editor template
MultiLine1.cshtml
andMultiLine2.cshtml
and in your view model you can useUIHint
to specify which editor template you want to use for that particular property. But you can specify only one template for one property. On different properties of same type, you can use different templates though.