如何使用ACE与我的ASP.NET MVC应用程序? [英] How do I use ACE with my ASP.NET MVC application?

查看:287
本文介绍了如何使用ACE与我的ASP.NET MVC应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 ACE 的在我的项目在网上code编辑器。我如何使用它在ASP.NET MVC?

I want to use the ACE online code editor in my project. How do I use it in ASP.NET MVC?

我要保存任何编辑与数据库中的编辑器中进行。我该怎么做呢?

I'd like to save whatever edits are made with that editor in the database. How do I do that?

推荐答案

让我们假设你有一个名为编辑在它的数据属性强类型的模型。现在使用正常< D​​IV> 加载数据:

Let's assume you have a strong typed model with a property called Editor with the data in it. Now use a normal <div> to load the data:

<div id="editor"><%=Model.Editor %></div>

现在您可以在地方使用JavaScript的div创建一个王牌编辑:

Now you can create an ace editor in place of the div with javascript:

<script src="src/ace.js" type="text/javascript" charset="utf-8"></script>
<script>
window.onload = function() {
    var editor = ace.edit("editor");
};
</script>

现在,当你想通过表单提交保存数​​据,例如,使用这样的绑定回模型的编辑属性:

Now when you want to save the data, for instance via a form post, use something like this to bind it back to the Editor property of the model:

<%=Html.HiddenFor(m=>m.Editor, new { @id = "hidden_editor" }) %>

<!-- this is jQuery, but you can use any JS framework for this -->
<script>
    $("form").submit(function () {
        $("#hidden_editor").val(editor.getSession().getValue());
    });
</script>

在你的控制器可以将数据立即保存到数据库中。

In your controller you can now save the data to the database

[HttpPost]
public ActionResult Index (IndexModel model) {
    var data = model.Editor;
    // save data in database
}

这篇关于如何使用ACE与我的ASP.NET MVC应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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