Html editor-HTMLBox under Asp.net mvc 4

Source: Internet
Author: User

1. Preparations
The extracted files are as follows:

2. Create an ASP. net mvc 2.0 Razor project and select "null.
A. Add A JQuery file, such:

B. Add an HtmlBox file, such:

Because of Path Problems, you may not be able to see the edited small image. Therefore, modify the path of the htmlbox. full. js image as shown in the selected line:

 
Note: To display the htmlboxlogoin the editing tool, you can delete the logo.gif in the imagesunder the htmlboxfolder.
3. Add a TestModel class to Modes with two attributes: Title and Content.
Public class TestModel
{
[Display (Name = "title")]
[Required]
Public string Title
{
Get;
Set;
}
[Display (Name = "content")]
[Required]
Public string Content
{
Get;
Set;
}
}
4. Create a Controller named Test with two actions
Public class TestController: Controller
{
Public ActionResult Index ()
{
TestModel tm = new TestModel ();
Tm. Title = "Title ";
Tm. Content = "This Is A <font size = '48'> test </font> ";
Return View (tm );
}
[HttpPost]
[ValidateInput (false)] // when the page submits an html Tag, It is not verified.
Public ActionResult Index (TestModel tm)
{
String content = tm. Content;
Return View ();
}}
5. Create a folder Test in the View and add Index. cshtml. The Code is as follows:
@ Model MVC4_HTMLBox.Models.TestModel
@{
Layout = null;
}
<! DOCTYPE html>
<Html>
<Head>
<Meta name = "viewport" content = "width = device-width"/>
<Title> Index </title>
<Script src = "~ /Script/jquery-1.7.1.min.js "> </script>
<Script src = "~ /HtmlBox/htmlbox. colors. js "> </script>
<Script src = "~ /HtmlBox/htmlbox. styles. js "> </script>
<Script src = "~ /HtmlBox/htmlbox. syntax. js "> </script>
<Script src = "~ /HtmlBox/xhtml. js "> </script>
<Script src = "~ /HtmlBox/htmlbox. full. js "> </script>
 
</Head>
<Body>
@ Using (Html. BeginForm ())
{
@ Html. LabelFor (mod => mod. Title)
<Br/>
@ Html. EditorFor (mod => mod. Title)
<Br/>
@ Html. LabelFor (mod => mod. Content) <br/>
// Standard htmlhelper, no matter whether the data is obtained from the Controller or submitted to the Controller
@ Html. EditorFor (mod => mod. Content)
<Br/>
<Br/>
<Input type = "submit" value = "submit"/>}
@ * The following code supports editor display *@
<Script>
$ ("# Content" ).css ("height", "600px" ).css ("width", "800px" ).html box ({
Toolbars :[
[
// Cut, Copy, Paste
"Separator", "cut", "copy", "paste ",
// Undo, Redo
"Separator", "undo", "redo ",
// Bold, Italic, Underline, Strikethrough, Sup, Sub
"Separator", "bold", "italic", "underline", "strike", "sup", "sub ",
// Left, Right, Center, Justify
"Separator", "justify", "left", "center", "right ",
// Ordered List, Unordered List, Indent, Outdent
"Separator", "ol", "ul", "indent", "outdent ",
// Hyperlink, Remove Hyperlink, Image
"Separator", "link", "unlink", "image"
 
],
[// Show code
"Separator", "code ",
// Formats, Font size, Font family, Font color, Font, Background
"Separator", "formats", "fontsize", "fontfamily ",
"Separator", "fontcolor", "highlight ",
],
[
// Strip tags
"Separator", "removeformat", "striptags", "hr", "paragraph ",
// Styles, Source code syntax buttons
"Separator", "quote", "styles", "syntax"
]
],
Skin: "blue"
});
</Script>
</Body>
</Html>
 
Tip:
Run the program, edit and submit. You can obtain the data of TestModel in the Index Action. You can see that the Content of tm is a Content with HTML tags.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.