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

2019-07-16 06:49发布

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?

2条回答
爷、活的狠高调
2楼-- · 2019-07-16 07:07

True... it'll output typically:

<input type="text />

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

查看更多
The star\"
3楼-- · 2019-07-16 07:08

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.

查看更多
登录 后发表回答