//官網下載:http://ckeditor.com/download
Nuget 套件管理工具下載:搜尋 HtmlSanitizationLibrary
//.cshtml
[View]
@using (Html.BeginForm("functionname", "MyBlog", FormMethod.Post, new { id = "FormNew" }))
{
@Html.TextAreaFor(model => model.content, new { id = "content", @name = "content" })
<script type="text/javascript">
CKEDITOR.replace('content', { width: '800px' });
</script>
}
//MyBlogController.cs
[Controller]
[HttpPost]
[ValidateInput(false)] //解決html1編碼問題
public ActionResult functionname(string Title, string content) //Title,content自動對應到html的id
{
int RtnCode = m.MyDataEdit(AID, Sanitizer.GetSafeHtmlFragment(Title),Sanitizer.GetSafeHtmlFragment( content));
}
於VS2010就可以透過NuGet幫網站專案安裝上 AntiXSS
程式中使用AntiXSS的 Sanitizer.GetSageHtmlFragement() 方法,取得安全的HTML區段內容。
參考連結:
ASP.NET MVC 3 使用 CKEditor
[config 全部可編輯的ToorBar功能]
Nuget 套件管理工具下載:搜尋 HtmlSanitizationLibrary
//.cshtml
[View]
@using (Html.BeginForm("functionname", "MyBlog", FormMethod.Post, new { id = "FormNew" }))
{
@Html.TextAreaFor(model => model.content, new { id = "content", @name = "content" })
<script type="text/javascript">
CKEDITOR.replace('content', { width: '800px' });
</script>
}
//MyBlogController.cs
[Controller]
[HttpPost]
[ValidateInput(false)] //解決html1編碼問題
public ActionResult functionname(string Title, string content) //Title,content自動對應到html的id
{
int RtnCode = m.MyDataEdit(AID, Sanitizer.GetSafeHtmlFragment(Title),Sanitizer.GetSafeHtmlFragment( content));
}
於VS2010就可以透過NuGet幫網站專案安裝上 AntiXSS
程式中使用AntiXSS的 Sanitizer.GetSageHtmlFragement() 方法,取得安全的HTML區段內容。
參考連結:
ASP.NET MVC 3 使用 CKEditor
[config 全部可編輯的ToorBar功能]
config.toolbar = 'Full';
config.toolbar_Full =
[
{ name: 'document', items : [ 'Source','-','Save','NewPage','DocProps','Preview','Print','-','Templates' ] },
{ name: 'clipboard', items : [ 'Cut','Copy','Paste','PasteText','PasteFromWord','-','Undo','Redo' ] },
{ name: 'editing', items : [ 'Find','Replace','-','SelectAll','-','SpellChecker', 'Scayt' ] },
{ name: 'forms', items : [ 'Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton',
'HiddenField' ] },
'/',
{ name: 'basicstyles', items : [ 'Bold','Italic','Underline','Strike','Subscript','Superscript','-','RemoveFormat' ] },
{ name: 'paragraph', items : [ 'NumberedList','BulletedList','-','Outdent','Indent','-','Blockquote','CreateDiv',
'-','JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock','-','BidiLtr','BidiRtl' ] },
{ name: 'links', items : [ 'Link','Unlink','Anchor' ] },
{ name: 'insert', items : [ 'Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak','Iframe' ] },
'/',
{ name: 'styles', items : [ 'Styles','Format','Font','FontSize' ] },
{ name: 'colors', items : [ 'TextColor','BGColor' ] },
{ name: 'tools', items : [ 'Maximize', 'ShowBlocks','-','About' ] }
];
參考連結:
---------------------------------------------------------------------
自訂版
config.toolbar = 'Cunstomer';
config.toolbar_Cunstomer =
[
{ name: 'document', items: ['Source', '-', 'Save', 'NewPage', 'DocProps', 'Preview', 'Print', '-', 'Templates'] },
{ name: 'clipboard', items: ['Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo'] },
{ name: 'editing', items: ['Find', 'Replace'] },
{ name: 'insert', items: ['Image', 'Flash', 'Table', 'Smiley', 'SpecialChar', '-', 'Link', 'Unlink'] },
'/',
{ name: 'styles', items: ['Font', 'FontSize'] },
{ name: 'colors', items: ['TextColor', 'BGColor'] },
{ name: 'basicstyles', items: ['Bold', 'Italic', 'Underline', 'Strike', '-', 'RemoveFormat'] },
{ name: 'paragraph', items: ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-', 'Blockquote', 'CreateDiv'] },
{ name: 'align', items: ['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'] }
];
留言
張貼留言