How to change Textbox to Text Areafor(value)

Topics: Customizing Orchard, Troubleshooting, Writing modules, Writing themes
Dec 27, 2011 at 4:46 PM

I have added a custom content part. a simple textbox called Description. However I would like to change this to an TextAreaFor(value).

 

I used shape tracing and created an alternate shape for the text box. But I am not sure how to go about making the change from textbox to textarea.

 

My modified code that doesn't work:

@using Orchard.Utility.Extensions;
@{
    string name = Model.Name;
    string value = Model.Value;
}
@if (HasText(name) && HasText(value)) {
<p class="text-field"><!--<span class="name">@name.CamelFriendly():</span>--> <span class="value">@Html.TextAreaFor(Model.Value)</span></p>
}

Original code from the Alt shape template:

@using Orchard.Utility.Extensions;
@{
    string name = Model.Name;
    string value = Model.Value;
}
@if (HasText(name) && HasText(value)) {
<p class="text-field"><span class="name">@name.CamelFriendly():</span> <span class="value">@value</span></p>
}

Anyone have any experience with Modifying a content part without building a custom content part from scratch?

Thanks

Oceantrain

Coordinator
Dec 27, 2011 at 10:08 PM

All overloads of TextAreaFor that I can see on MSDN documentation take an expression. I don't see it in your usage, so this shouldn't even compile. Does it? Can you provide more information about any error you're seeing?

Dec 27, 2011 at 10:14 PM

That's correct. I tried using a lambda expression.

Html.TextAreaFor(Model => Model.Value)

Error: Model.Value does not exist in current context.

Is this because this is a dynamic property set at the top of the page. Has anyone (yourself) ever tried to
change the default content field (textbox) into a larger text area?
I just need a little bigger text box to write descriptions.
Coordinator
Dec 27, 2011 at 11:18 PM

Cast it before you use it in a Lambda. Lambdas don't like dynamics. Then again, why do you need to use TextAreaFor? There is a perfectly good TextArea method, and you can also use a plain <textarea> tag.