Vishal
Vishal

Reputation: 12369

How to use rich text in htmlhelpers or use html and links in asp.net mvc 2?

Hi all I wanted to allow the users to enter html and links in textbox. How can I achieve something like this in ASP.NET MVC 2? I have something like this now...

<div class="editor-field">
                <%= Html.TextAreaFor(model => model.Description) %>
                <%= Html.ValidationMessageFor(model => model.Description) %>
 </div>

I found this link - Allow HTML in text boxes

But I am using ASP.NET MVC 2 and I am looking for something that MVC provides for this by default like a rich textbox or something and not just disable the validation.

Upvotes: 1

Views: 1018

Answers (1)

John Hartsock
John Hartsock

Reputation: 86882

you could Encode the Value of the text area before posting the form(ClientSide), and then decode the value of the textarea when displaying the form(ServerSide). This would allow you to keep the validation there.

However it is good to mention that if you are using validation. What validator's are you using? Required, Length, some Custom Validator? I only mention this because if you are not using any actual validators on the field Description then maybe you do want to disable validation on that field. If you are using some Validators and you decide to encode on the client side and decode on the serverside then you need think about how the encoding will effect your validation code.

Upvotes: 1

Related Questions