简体   繁体   中英

using c# in TinyMCE

I am using the tinyMCE editor. In the code, I have function called getPhone() that return string depend on the Url. So in the TinyMCE, I added source code like the following: <div>@(Client.Helpers.Functions.getPhone())</div> . I wanted that this code will show the return value from getPhone() function. unfortunately, it's render it to string, and not to C# code. so in the website you can see this as a text: @(Client.Helpers.Functions.getPhone()), does anybody know why?

Do you mean by "@(...)" as C# standard inline code (ie <%= %>)? If so, remember that when ASP.Net is rendering your page it puts different content at appropriate positions in the page from source data. This implies that your C# related codes that are presented in the Tiny Editor will NOT be recognized for rendering to Html at render time.

To solve the problem, you would have 2 options:

1) Assume a custom phrase for phone like "[PHONE]" and find for that phrase in any text that is pulled out from DB and replace with the appropriate phone number based on your logic

or

2) Extend the TinyMCE javascript lib and add a custom button that inserts a script block and a tag in the caret position in the editor. The script makes a callback to server and calls the getPhone() method and puts the result in the mentioned , with considering unique id for the whole process!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM