Reputation: 25
hello I am very new to asp.net mvc I need to save the data given in ck editor
i did like this i downloaded the ck editor from the internet and pasted in my solution explorer given the path in view
path is like this:
<script src="~/ckeditor/ckeditor.js"></script>
written razor code for text area:
@Html.TextArea("editor", new {@class = "ckeditor", @id = "aboutme"})
how to save this data in database
Upvotes: 1
Views: 5871
Reputation: 18873
Basic usage of ckeditor is as follows:
@Html.TextArea("editor", htmlAttributes: new { name = "editor", id = "editor", rows = "10", cols = "180" })
and configure your ckeditor as :
<script>
CKEDITOR.replace('editor',
{
height: 450
});
</script>
and while posting data to httpPost controller do this :
[ValidateInput(false)] <-------
[HttpPost]
public ActionResult YourController(FormCollection formValues)
{
//You can get value of ckeditor as
var temp = formValues["editor"]; //it will have complete data inside ckeditor you can save it to database as the way you want.
}
Make sure to add ValidateInput(false) because ckeditor provides output as html with html tags but in asp.net mvc due to security reasons they give exception when we post html tags so ValidateInput(false) will solve the purpose.
Make sure to add complete folder named ckeditor in your root folder of your project and also provide reference of js file in your view
Upvotes: 1