Abdur Rahim
Abdur Rahim

Reputation: 4021

creating textarea with htmlhelper in asp .net mvc 4

USING : ASP .NET MVC 4 in one of my page i need a textarea with a certain width and height using html helper class. some of my code is given below :

    <div class="editor-label">
        @Html.LabelFor(model => model.MailSubject)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.MailSubject)
        @Html.ValidationMessageFor(model => model.MailSubject)
    </div>

    <div class="editor-label">
        @Html.LabelFor(model => model.MailBody)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.MailBody)
        @Html.ValidationMessageFor(model => model.MailBody)
    </div>

    <div class="editor-label">
        @Html.LabelFor(model => model.Content)
    </div>
    <div class="editor-field1">
        @Html.EditorFor(model => model.Content)
        @Html.ValidationMessageFor(model => model.Content)
    </div>

I am wondering how I define the size(width/hide) of the editorfor(model.content)?

Upvotes: 3

Views: 8743

Answers (3)

Evidica
Evidica

Reputation: 1464

I realize this question is over a year old but just in case anyone is looking for the answer, here it is:

Html.TextAreaFor(model => model.Field, new { rows = "", cols = "", style = "width: 90%; height: 50px;" })

You can either apply the styles inline or use the class declaration. This will render the textarea on the page like so:

<textarea class="swiper-no-swiping" name="model.Field" cols="" rows="" style="width: 90%; height: 50px;"></textarea>

Upvotes: 5

Nick Fleetwood
Nick Fleetwood

Reputation: 531

I had this problem. I'm a newb, so I'm not really sure, but using the following I was able to adjust the height...

@Html.TextAreaFor(model => model.FullItinerary, 20, 10, null)

I still don't know how to adjust width, my current google mission...

Upvotes: 2

Ed Charbeneau
Ed Charbeneau

Reputation: 4634

Write a customer helper, or extend the functionality of the TextAreaFor helper.

Here is a resource to help you create a custom helper: http://www.simple-talk.com/dotnet/asp.net/writing-custom-html-helpers-for-asp.net-mvc/

Upvotes: 0

Related Questions