在我的MVC应用程序中,我想在CKEDITOR中显示提取的文本。但文本显示在文本区而不是编辑器中我的控制器代码是:
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();
}
}
textarea样式,javascript事件可以在视图上完成。将文本传递给视图并显示在文本区域上。所有的事件和样式都可以写在视图上。该编辑器可以加载到文本区上的ready函数。请仔细阅读以下内容。
.Net MVC的CK编辑器
为了更好地在您的项目中实现CKEditor,请查看以下链接中的答案
CKEditor MVC 3实现需要帮助
编辑. .
<%= 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>
您将在视图编辑器中从控制器获取文本。确保您有所有必要的ckeditor脚本和正确提供的位置