将内容富文本编辑器保存到mysql数据库中的blob字段 [英] Save content rich text editor to blob field in mysql database

查看:2737
本文介绍了将内容富文本编辑器保存到mysql数据库中的blob字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将内容从富文本编辑器(在我的情况下为ckeditor)保存到数据库中的Blob字段中。

I'm trying to save the content from a rich text editor (ckeditor in my case) to my a blob field in my database.

这是我的ViewModel:

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>

我在控制器中的操作:

[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);
    }

但是在我的存储库中,我得到:无法转换类型'string'到'byte []'

But in my repository I get : Cannot convert type 'string' to 'byte[]'

存储库:

public void AddArticle(string Title, string Description, string ArticleBody)
    {
        item Item = new item()
        {
            item_title = Title,
            item_description = Description,
            article_body = ArticleBody,
            item_createddate = DateTime.Now,
            item_approved = false,
            user_id = 1,
            district_id = 2,
            link = "",
            type = GetType("Article")
        };

        try
        {
            AddItem(Item);
        }

        catch (ArgumentException ae)
        {
            throw ae;
        }
        catch (Exception)
        {
            throw new ArgumentException("The authentication provider returned an error. Please verify your entry and try again. " +
                "If the problem persists, please contact your system administrator.");
        }

        Save();
        // Immediately persist the User data

    }

Can有人给我一个开始或帮助我吗?

Can somebody give me a start or help me with this?

推荐答案

应该是

Public void AddArticle(string title, string  Description, string ArticleBody)
{
//logic
}

我认为您的存储库方法对于任何一个参数都具有字节类型。检查是否像我的方法格式一样。

I think your repository method have byte type for any one argument . Check that like my method format .

编辑:

检查您的<$您的数据库中的c $ c> article_body 列数据类型?它应该我 Nvarchar(Max)

Check your article_body column data type in your database? its should me Nvarchar(Max) .

这篇关于将内容富文本编辑器保存到mysql数据库中的blob字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆