Wednesday, 21 August 2013

Save content rich text editor to blob field in mysql database

Save content rich text editor to blob field in mysql database

I'm trying to save the content from a rich text editor (ckeditor in my
case) to my a blob field in my database.
This is my ViewModel:
public class ArticleViewModel
{
[Required]
[Display(Name = "Title")]
public string Title { get; set; }
[Required]
[Display(Name = "Description")]
public string Description { get; set; }
[Required]
[Display(Name = "Article Body")]
public string ArticleBody { get; set; }
}
The Article Body is my rich text field like this in my view:
<div class="editor-label">
@Html.LabelFor(model => model.ArticleBody)
</div>
<div class="editor-field">
@Html.TextAreaFor(model => model.ArticleBody, new { placeholder =
"Type the content of the article", @class = "ckeditor" })
@Html.ValidationMessageFor(model => model.ArticleBody, string.Empty)
</div>
In my Action in my Controller:
[HttpPost]
public ActionResult Create(ArticleViewModel model)
{
if (ModelState.IsValid)
{
try
{
// Get the userID who created the article
User usr = userrepo.FindByUsername(User.Identity.Name);
model.UsernameID = usr.user_id;
repository.AddArticle(model.Title, model.Description,
model.ArticleBody);
}
catch (ArgumentException ae)
{
ModelState.AddModelError("", ae.Message);
}
return RedirectToAction("Index");
}
return View(model);
}
But in my repository I get : Cannot convert type 'string' to 'byte[]'
Can somebody give me a start or help me with this?

No comments:

Post a Comment