ASP.NET MVC support for HTML output (as opposed to XHTML)

老子叫甜甜 提交于 2019-12-24 01:45:28

问题


It seems to me that ASP.NET MVC Html Helpers only output XHTML-like tags (closed empty elements), which is not valid HTML.

Is there support for HTML output in ASP.NET MVC?


回答1:


True... it'll output typically:

<input type="text />

You could certainly write your own HTML Helpers to cover any cases you want.




回答2:


As pcampbell hinted, you probably need to write your own Html helper to do this. However, it doesn't have to be too hard - if you notice you need one, for example for an <input> element, you could simply do this:

 public static class Html4Extensions
     public string Html4TextBox(this HtmlHelper helper, string name)
     {
         return helper.TextBox(name).Replace("/>", ">");
     }
 }

And then you do the same for every overload you need.



来源:https://stackoverflow.com/questions/967256/asp-net-mvc-support-for-html-output-as-opposed-to-xhtml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!