Property Being Html encoded

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
12 年 前
Hello,

Based on Skyler's "Updating an existing entity. How to add a new property"  tutorial (and a lot of help from the gentleman himself) I was able to sucessfully add 3 new properties to the PoductVariant entity. The code is working as expected except for one thing... when I edit the properties in the admin view the values I enter get saved to the database as encoded.

In  my view (\Presentation\Nop.Web\Administration\Views\Shared\_ProductVariantInfo.cshtml) I coded of my properties to be displayed using the rich editor as follows:
<tr>
   <td class="adminTitle">
      @Html.NopLabelFor(model => model.myVariant1):
   </td>
   <td class="adminData">
      @Html.EditorFor(x => x.Specs, "RichEditor")
      @Html.ValidationMessageFor(model => model.myVariant2)
   </td>
</tr[/b]>[/i]

I my model (\Presentation\Nop.Web\Administration\Models\Catalog\ProductVariantModel.cs) I coded the properties as follows:

[NopResourceDisplayName("Admin.Catalog.Products.Variants.Fields.myVariant1")]
[AllowHtml]
public string Specs { get; set; }

[NopResourceDisplayName("Admin.Catalog.Products.Variants.Fields.myVariant2")]
[AllowHtml]
public string Downloads { get; set; }

The view displays fine and I can edit the fields and everything looks and works great until I do a save (or save and continue). At that point the data I entered gets Html encoded before it is stored in the database and displayed back to the screen. Code which should be stored like...

<strong>Size: </strong>10" x 7" with 12" Handle<strong>Unit Weight:</strong> .2 lbs.

ends up looking like...

&lt;strong&gt;Size: &lt;/strong&gt;10" x 7" with 12" Handle&lt;strong&gt;Unit Weight:&lt;/strong&gt; .2 lbs.


I found the following comment in the RichEditor.cshtml file, and think it may be the answer to my problem, I just can't figure out where to go with it....

@(
Html.Telerik().Editor().Name(clientId)
/*.Encode(false) weird. Settings "Encode(false)" doesn't work on category & product details page
Now we have to manually decode values*/

It looks like I need to manually decode my values once they have been returned, and before they're stored in the DB, but I can't find the place I should be doing it. The only other field I see on the admin product and category details pages that uses the rich editor is FullDescription, but I don't see anything different in the way it's coded as apposed to what I've done.

Can anyone point me in the right direction?

Thanks.

Tim
12 年 前
Hello again,

Is the person who wrote the RichEditor.cshtml file around? If so, this would porbably be a quick and easy one for who ever it was to answer.

Thanks.
12 年 前
Telerik editor (2.00-2.30) doesn't work well with encoded strings. That's why you have to manually decode strings (HttpUtility.HtmlDecode) in \Presentation\Nop.Web\Administration\Controllers\CategoryController.cs file. Look at 'Create' and 'Edit' methods (POST handlers).

That's why we moved to TinyMCE editor in upcoming 2.40 version
12 年 前
Thank you. thank you, thank you... just what I needed.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.