如何在 htmlhelpers 中使用富文本或在 asp.net mvc 2 中使用 html 和链接?
大家好,我想允许用户在文本框中输入 html 和链接。如何在 ASP.NET MVC 2 中实现类似的功能?我现在有这样的东西......
<div class="editor-field">
<%= Html.TextAreaFor(model => model.Description) %>
<%= Html.ValidationMessageFor(model => model.Description) %>
</div>
我找到了这个链接 - 允许文本框中出现 HTML
但我使用的是 ASP.NET MVC 2,我正在寻找 MVC 默认为此提供的东西,例如富文本框或其他东西,而不仅仅是禁用验证。
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.
您可以在发布表单(客户端)之前对文本区域的值进行编码,然后在显示表单(服务器端)时对文本区域的值进行解码。这将允许您将验证保留在那里。
不过,如果您正在使用验证,那么值得一提的是。您使用什么验证器?必需、长度、一些自定义验证器?我只是提到这一点,因为如果您没有在“描述”字段上使用任何实际验证器,那么您可能确实想禁用该字段上的验证。如果您正在使用一些验证器,并且决定在客户端进行编码并在服务器端进行解码,那么您需要考虑编码将如何影响您的验证代码。
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.