Writing microdata programmatically (C# / ASP.NET)

纵饮孤独 提交于 2019-12-23 05:28:00

问题


Is it possible to write 'value-less' attributes to WebControl types?

i.e. going from

1 = var div = new WebControl(HtmlTextWriterTag.Div);

2 = ???

3 = Rendered output: <div itemscope></div>


回答1:


You can created control (E.g. SomeMicroDataWebControl) derived from WebControl and overrride method "Render". In "Render" you define how your control will look like on page. Then add this class to a page or another control.




回答2:


If you're using ASP.NET MVC take a look at my blog post:

ASP.NET MVC: Add HTML5 Microdata to your applications using Metadata Providers

Hope it helps!




回答3:


You can create a System.Web.UI.HtmlControls.HtmlGenericControl control and set anything you like within it. W3C though recommends setting a data or role attributes, so you'd have <div role-scope='item'></div>



来源:https://stackoverflow.com/questions/6495369/writing-microdata-programmatically-c-asp-net

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