0

在我的 MVC 应用程序中,我想在 CKEDITOR 中显示提取的文本。但是文本在 textarea 中而不是在编辑器中显示我的控制器代码是:

 public ActionResult ExtractText(string fn)
    {

        string extFile = Server.MapPath(_fileUploadPath + fn);
        string filePath = Path.Combine(HttpContext.Server.MapPath(_fileUploadPath), Path.GetFileName(fn));
        if (filePath != null)
        {

            SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();
            f.OpenPdf(System.IO.File.ReadAllBytes(filePath));

            string text = f.ToText();
            string sValue = "<textarea id = \"temp_edit\" name=\"content\" cols=\"73\" rows=\"15\">" + text + "</textarea> <script type=\"text/javascript\">CKEDITOR.replace('temp_edit');</script><input class=\"margin-top-05 green_button\" type=\"button\" value=\"Save\" onclick=\"save_file()\" /><a class=\"close\" onclick=\"parent.$.fancybox.close();\"><img class=\"close_image\" title=\"close\" src=\"../images/closelabel.gif\" style=\"width: auto; height: auto; position: absolute; bottom: 0px; right: 0px;\"></a>";
           return Content(sValue);
        }
        else
        {
            TempData["UploadValidationMessage_Failure"] = "File does not exist";
            return View();

        }
    }
4

1 回答 1

4

textarea 样式、javascript 事件可以在您的视图上完成。将文本传递给视图并将其显示在 textarea 上。您的所有事件和样式都可以写在视图上。ckeditor 可以加载到 textarea on ready 函数。请通过以下。

.Net MVC 的 CK 编辑器

如需在您的项目中实现 CKEditor 的更好方法,请浏览以下链接中的 aswer

CKEditor MVC 3 implementationaion 需要帮助

编辑..

<%= Html.ActionLink("Extract Text", "ExtractText", new { fn = file })%>

带你去你的功能。

可以说,您有一个模型 NewContent

public class NewContent
{
 public string Text
    {
        get;
        set;
    }
}

从控制器返回带有文本的 NewContent 对象。

 public ActionResult ExtractText(string fn)
    {
        string extFile = Server.MapPath(_fileUploadPath + fn);
        string filePath = Path.Combine(HttpContext.Server.MapPath(_fileUploadPath), Path.GetFileName(fn));
        if (filePath != null)
        {
            SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();
            f.OpenPdf(System.IO.File.ReadAllBytes(filePath));
            string text = f.ToText();
            NewContent content = new NewContent();
            content.Text = text;
            return View(content);
        }
        else
        {
            TempData["UploadValidationMessage_Failure"] = "File does not exist";
            return View();

        }
    }

在您看来,添加以下内容

 <script src="ckeditor/ckeditor.js"></script>
 <script src="ckeditor/adapters/jquery.js"></script>

<%=Html.TextAreaFor(c => c.Text) %>

 <script type="text/javascript">
    $(function () {
        $('#Text').ckeditor();
    });
</script>

您将在 ck 编辑器的视图中从控制器获取文本。确保您已正确提供所有必要的 ckeditor 脚本及其位置

于 2013-03-20T06:48:03.400 回答