Close

Problem With HTML Editor For CreateOrUpdate Forum Post

Ebrahim
8 years ago
#12053 Quote
Avatar
  • 25
Hi
I was changed source view model for I can insert html code in post text.

Every thinks is right but I have littel problem.

My edited code on _CreateUpdatePost.cshtml
<div class="inputs">
          @if (EngineContext.Current.Resolve<IWorkContext>().CurrentCustomer.IsInCustomerRole("ForumModerators"))
          {            
            @Html.EditorFor(model => model.Text , "RichEditor")            
          }
          else
          {
            if (Model.ForumEditor == EditorType.BBCodeEditor)
            {            
              @Html.BBCodeEditor("Text")            
            }
            @Html.TextAreaFor(model => model.Text, new { @class = "forum-post-text", TextMode = "MultiLine" })                    
          }
                    
                </div>


and _ForumPost.cshtml
<div class="posttext">
          @Html.Raw(HttpUtility.HtmlDecode(Model.FormattedText))                
            </div>



Now I can insert html code on edit post page and is very good view. But in view post added automatic very <br> tag when use table.

I think this line not work corectly
@Html.Raw(HttpUtility.HtmlDecode(Model.FormattedText))


Please help me
Ebrahim
8 years ago
#12054 Quote
Avatar
  • 25
In Editor:


In View Post page:
Deni
8 years ago
#12059 Quote
Avatar
  • Moderator
  • 389
Hi, 

Have you tried to click on the editor Tools > Source code and see if these <br/> tags are available.

Another thing you can try is to just print the text like this, because it should be already escaped and safe for printing:
@Model.FormattedText


I hope this helped !
Best Regards,
Mladen Staykov
Nop-Templates.com
Ebrahim
8 years ago
#12061 Quote
Avatar
  • 25
Deni wrote:
Hi, 

Have you tried to click on the editor Tools > Source code and see if these <br/> tags are available.

Another thing you can try is to just print the text like this, because it should be already escaped and safe for printing:
@Model.FormattedText


I hope this helped !



Thank you very much for answer.
Yes< I checked source code in editor and not have <br> tag:


And I try @Model.FormattedText but text not decode:

Deni
8 years ago
#12069 Quote
Avatar
  • Moderator
  • 389
Hi, 

I think you should change the property FormattedText in the ForumPostModel to allow HTML.
Best Regards,
Mladen Staykov
Nop-Templates.com
Ebrahim
8 years ago
#12075 Quote
Avatar
  • 25
Deni wrote:
Hi, 

I think you should change the property FormattedText in the ForumPostModel to allow HTML.


thanks for answer. But Can you tell me How can I do it? How can change the property?
Deni
8 years ago
#12080 Quote
Avatar
  • Moderator
  • 389
Ebrahim wrote:
thanks for answer. But Can you tell me How can I do it? How can change the property?


Hi, 

Go to the ForumPostModel class and make the property "FormattedText" to have attribute [AllowHtml]. You will need "using System.Web.Mvc;".

I hope this helped !
Best Regards,
Mladen Staykov
Nop-Templates.com
Ebrahim
8 years ago
#12100 Quote
Avatar
  • 25
Deni wrote:
thanks for answer. But Can you tell me How can I do it? How can change the property?

Hi, 

Go to the ForumPostModel class and make the property "FormattedText" to have attribute [AllowHtml]. You will need "using System.Web.Mvc;".

I hope this helped !


Please Help me without need edit source code.
Ebrahim
8 years ago
#12101 Quote
Avatar
  • 25
Ebrahim wrote:
thanks for answer. But Can you tell me How can I do it? How can change the property?

Hi, 

Go to the ForumPostModel class and make the property "FormattedText" to have attribute [AllowHtml]. You will need "using System.Web.Mvc;".

I hope this helped !

Please Help me without need edit source code.


I've found a temporary solution :
@Html.Raw(HttpUtility.HtmlDecode(@Model.FormattedText).Replace("<br />","" ))