问题描述
我想读取一个静态txt文件,进行编辑,然后将其再次保存为asp .net Core MVC Web应用程序中的txt文件。
我想知道是否可以通过使用可用的富文本编辑器之一(例如TinyMCE,CKEditor或Quill)来实现这一目标。
下面是我当前拥有的代码。
控制器
public IActionResult Index()
{
return View(new Script());
}
[HttpPost]
public ActionResult Index(Script script)
{
return View(script);
}
private void btnRead_Click(object sender,EventArgs e)
{
if (File.Exists(fileLoc))
{
using (TextReader tr = new StreamReader(fileLoc))
{
MessageBox.Show(tr.ReadLine());
}
}
}
课程
public class Script
{
public int id { get; set; }
[AllowHtml]
public string code { get; set; }
}
查看
@model Models.Script
@{
ViewData["Title"] = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<body>
@using (Html.BeginForm("Index","Scripts",FormMethod.Post))
{
@Html.LabelFor(m => m.code)<br/>
@Html.TextAreaFor(m => m.code)
@Html.ValidationMessageFor(m=>m.code,"",new { @class = "error" })
<br/><br/>
<input type="submit" value="Submit" />
<span>@Html.Raw(Model.code)</span>
}
</body>
@section Scripts{
<script src="https://cdn.tiny.cloud/1/7wyujejhpvi3ixga3ss1q5gqwvocaiozzy83w2gvwcd004s4/tinymce/5/tinymce.min.js" referrerpolicy="origin"></script>
<script>
tinymce.init({
selector: 'textarea',plugins: 'a11ychecker advcode casechange formatpainter linkchecker autolink lists checklist media mediaembed pageembed permanentpen powerpaste table advtable tinycomments tinymcespellchecker',toolbar: 'a11ycheck addcomment showcomments casechange checklist code formatpainter pageembed permanentpen table',toolbar_mode: 'floating',tinycomments_mode: 'embedded',tinycomments_author: 'Author name',});
</script>
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)