How can I get the tinymce HTML content from within a C# ASP.Net application?

老子叫甜甜 提交于 2020-01-06 15:25:27

问题


I have a tinymce editor and I am wanting to grab the HTML contents of the editor within my C# ASPX code - but I am not entirely sure on the right way of doing this?

Can somebody please suggest a best practice?

I know I can get the HTML Content by calling this from javascript...but how would I pass that result back to my ASP.NET C# for storing in a database for example:

tinymce.activeEditor.getContent()

回答1:


Set your Page validate request to false first:

<%@ Page ValidateRequest="false" ..

then add an id and runat property to your textarea:

<textarea id="txtEditor" runat="server" ... ></textarea>

Let's say on a button click you want to grab the information like this:

    protected void Button1_Click(object sender, EventArgs e)
    {
        string text1 = txtEditor.InnerHtml;  //includes HTMLs
        string text2 = txtEditor.InnerText;  //just plain text

        //store the value into the database here
    }

You could also add the first line into your web.config file if your are using .NET Framework 4 +

<system.web>
     <pages validateRequest="false" />
     <httpRuntime requestValidationMode="2.0" />
     ....

And if you do not want to have that globally you could point it to the page only using web.config as well:

Just add this one at the very end of your web.config file just before the </configuration>

 ....
 <location path="WebForm2.aspx"> <!-- add your page path here -->
  <system.web>
    <pages validateRequest="false" />
    <httpRuntime requestValidationMode="2.0" />
  </system.web>
 </location>
</configuration>



回答2:


Assuming you've bound TinyMCE to a textarea with runat="server", then in C# you can access the HTML via the textarea's InnerHtml property.



来源:https://stackoverflow.com/questions/24643595/how-can-i-get-the-tinymce-html-content-from-within-a-c-sharp-asp-net-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!