C#網頁模板引擎 SharpDOM

openkk 13年前發布 | 68K 次閱讀 C# 模板引擎

SharpDOM 可以讓你直接使用 C# 的語法來編寫網頁,舉個例子:

下面是一段HTML代碼:

<html>
    <head>
        <title>Title of the page</title>
        <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
        <link href="css/style.css" rel="stylesheet" type="text/css">
        <script href="/JavaScripts/jquery-1.4.2.min.js" type="text/javascript">
    </head>
    <body>
        <div>
            <h1>Test Form to Test</h1>
            <form id="Form1" type="post">
                <label>Parameter</label> =
                <input type="text">Enter value</input>
                <input type="submit" text="Submit !" />
            </form>
            <div>
                <p>Textual description of the footer</p>
                <a href="http://google.com">
                    <span>You can find us here</span>
                </a>
                <div>
                    Another nested container
                </div>
            </div>
        </div>
    </body>
</html>
使用 SharpDOM 來編寫的話,就變成了
html[
    head[
        title[ "Title of the page" ],
        meta.attr(http-equiv: "contenttype", content: "html", charset: "utf-8"),
        link.attr(href: "css/style.css", rel: "stylesheet", type: "css"),
        script.attr(href:"/JavaScripts/jquery-1.4.2.min.js", type: "javascript")
    ],
    body[
        div[
            h1[ "Test Form to Test" ],
            form.attr(id: "Form1", type: "post")[
                label[ "Parameter" ], "=", input.attr(type:"text", value: "Enter value"), br,
                input.attr(type: "submit", value: "Submit !")
            ],
            div[
                p[ "Textual description of the footer" ],
                a.attr(href: "http://google.com" )[
                    span[ "You can find us here"]
                ]
            ],
            div[ "Another nested container" ]
        ]
    ]
]

項目主頁:http://www.baiduhome.net/lib/view/home/1322965260296

 本文由用戶 openkk 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!