How do I use ACE with my ASP.NET MVC application?

前端 未结 3 1902
孤城傲影
孤城傲影 2021-02-14 03:32

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 d

3条回答
  •  感情败类
    2021-02-14 04:18

    Here is a solution using most recent technologies (Razor/MVC/Ajax) :

        $(document).ready(function() {
            $("#btnSave").on("click", function () {                
                    $.ajax({
                        url: '@Url.Action("YourAction", "YourController")',
                        type: 'POST',
                        data: { id: @Model.ID,
                                html: ace.edit("editor").getValue() },
                        cache: false,
                        success: function (response) {
                            alert("Changes saved.");
                        }                        
                    });
            });
        });
    

    In Controller :

        [AjaxAuthorize]
        [HttpPost, ValidateInput(false)]
        public ActionResult YourAction(string id, string html)
        {
            if (id == null || String.IsNullOrEmpty(id))
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            // do you stuff
        }
    

提交回复
热议问题