The only way I can come up with is to use html comments in combination with razor comments.
First you would create a razor template:
@{ Layout = null; } <!DOCTYPE html> <html> <head> <title>Index</title> </head> <body> <table> <tbody> <tr><td>X</td><td>Y</td></tr> @**@ <tr> <td class="row">@Html.Raw(x)</td> <td class="row">@Html.Raw(y)</td> </tr> @**@ </tbody> </table> </body> </html>
The code above is valid and will display without errors. But when you put it in the html editor, it will be reordered by the browser, so you will need to change it immediately before displaying it for editing so that the razor comments are deleted and only the html comments remain.
So, as soon as you delete the razor comments by replacing all instances of @*<!--*@ with <!-- and all instances of @*-->*@ with --> , you should have the following
<!DOCTYPE html> <html> <head> <title>Index</title> </head> <body> <table> <tbody> <tr><td>X</td><td>Y</td></tr> <tr> <td class="row">@Html.Raw(x)</td> <td class="row">@Html.Raw(y)</td> </tr> </tbody> </table> </body> </html>
This will be displayed in the html editor and will not be crippled by the browser, as Alfonso pointed out, an example of this is at jsfiddle http://jsfiddle.net/wPGLd/3/
After editing is complete, you will need to grab the html and reapply the razor comments, replacing all instances of <!-- with @*<!--*@ and all instances of --> with @*-->*@
The html interception before and after entering ckeditor is pretty straight forward and well documented. I found the following article which explains a little how to get the contents of ckeditor when submitting
How to update CKEditor content on submit form - equivalent to OnAfterLinkedFieldUpdate FCKEditor
The next question also covers this
Refresh the contents of the editor immediately before saving it in the CKEditor plug-in
user2985029
source share