0

コンテンツをリッチ テキスト エディター (私の場合は ckeditor) からデータベースの blob フィールドに保存しようとしています。

これは私のビューモデルです:

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

}

記事の本文は、私の見解では次のようなリッチ テキスト フィールドです。

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

しかし、私のリポジトリでは次のようになります: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

    }

誰かが私に始めさせたり、これを手伝ってくれませんか?

4

1 に答える 1