Write HTML to string

前端 未结 18 1514
一生所求
一生所求 2020-12-13 00:04

I have code like this. Is there a way to make it easier to write and maintain? Using C# .NET 3.5.

string header(string title)
{
    StringWriter s = new Stri         


        
18条回答
  •  爱一瞬间的悲伤
    2020-12-13 00:28

    You could use some third party open-source libraries to generated strong typed verified (X)HTML, such as CityLizard Framework or Sharp DOM.

    Update For example

    html
        [head
            [title["Title of the page"]]
            [meta_(
                content: "text/html;charset=UTF-8",
                http_equiv: "Content-Type")
            ]
            [link_(href: "css/style.css", rel: "stylesheet", type: "text/css")]
            [script_(type: "text/javascript", src: "/JavaScript/jquery-1.4.2.min.js")]
        ]
        [body
            [div
                [h1["Test Form to Test"]]
                [form_(action: "post", id: "Form1")
                    [div
                        [label["Parameter"]]
                        [input_(type: "text", value: "Enter value")]
                        [input_(type: "submit", value: "Submit!")]
                    ]
                ]
                [div
                    [p["Textual description of the footer"]]
                    [a_(href: "http://google.com/")
                        [span["You can find us here"]]
                    ]
                    [div["Another nested container"]]
                ]
            ]
        ];
    

提交回复
热议问题