Using Wyzz Web-based HTML editing control in ASP.NET MVC
I recently had to put out a web-based single page application (SPA) on short notice. To make that happen, I knew I had to use some open-source controls. One was the jsTree treeview control (which I wrote about on this blog - Using jsTree with ASP.NET MVC) and another was the Wyzz WYSIWYG web-based editing control for HTML.
From their site, “Wyzz is an ultra-small, very light WYSIWYG (What You See Is What You Get) Editor for use in your web applications. It's written in JavaScript, and is free (as in speech and as in beer) for you to use in your web applications and/or alter to your needs (see the license conditions).”
As you can see in the example above, I’ve chosen to use an AngularJS control to define the behaviour of the save button. In the JavaScript I define a server-side controller function (ASP.NET in this case) and I send it the content of the control by accessing the HTML element that the control is using.
Update: Here’s the basic format of the server-side part:
To customize your Wyzz controls, you can edit the wyzz.js file. If you have any issues, refer to the Wyzz discussion forum.
From their site, “Wyzz is an ultra-small, very light WYSIWYG (What You See Is What You Get) Editor for use in your web applications. It's written in JavaScript, and is free (as in speech and as in beer) for you to use in your web applications and/or alter to your needs (see the license conditions).”
Naturally, the first step to add a reference to the wyzz.js script file. Once you have that, you just need to add the control to an HTML element. Finally, it’s a simple matter of adding some JavaScript to “make_wyzz” the control.
<script language="JavaScript" type="text/javascript" src="~/Home/wyzz.js">script>
<textarea name="textEditor" id="textEditor" rows="10" cols="40">No file loaded...textarea><br />
<script language="javascript1.2">make_wyzz('textEditor');
script><div ng-controller="EditorCtrl"> <form novalidate class="simple-form"> <button ng-click="saveFileContent()">savebutton> form>div>
As you can see in the example above, I’ve chosen to use an AngularJS control to define the behaviour of the save button. In the JavaScript I define a server-side controller function (ASP.NET in this case) and I send it the content of the control by accessing the HTML element that the control is using.
$scope.saveFileContent = function () {
$http.post('/Home/SaveFileContent', { filePath: document.getElementById("multilingualfile").innerHTML, content: document.getElementById("wysiwyg" + "textEditor").contentWindow.document.body.innerHTML, title: document.getElementById("titleHtml").value })
.then(
function (response) {
alert("File Save Result: " + response.data.Result);
},
function (data) {
alert("Error saving file content");
}
);
}
Update: Here’s the basic format of the server-side part:
[HttpPost]
public ActionResult SaveFileContent(string filePath, string content, string title)
{
try
{
...
return Json
(
new
{
Result = "Success",
}
);
}
catch (Exception ex)
{
...
return Json
(
new
{
Result = "Error saving content: " + ex.ToString(),
}
);
}
}
To customize your Wyzz controls, you can edit the wyzz.js file. If you have any issues, refer to the Wyzz discussion forum.