asp.net-mvc – 如何从对象HtmlAttributes中获取值
发布时间:2020-05-23 12:13:11 所属栏目:asp.Net 来源:互联网
导读:在asp.net mvc我总是看到内置的html帮助他们总是有对象htmlAttirbutes。 那么我通常会做新的{@id =“test”,@ class =“myClass”}。 如何在我自己的html帮助程序中提取这样的参数? 像我正在使用的“HtmlTextWriterTag”是他们的一种方式,我可以把这整个对
|
在asp.net mvc我总是看到内置的html帮助他们总是有对象htmlAttirbutes。 那么我通常会做新的{@id =“test”,@ class =“myClass”}。 如何在我自己的html帮助程序中提取这样的参数? 像我正在使用的“HtmlTextWriterTag”是他们的一种方式,我可以把这整个对象传递给作家,它弄清楚了什么? 这又如何与大型html帮助者合作? 像我正在制作一个html助手,它使用所有这些标签。 Table thead tfooter tbody tr td a img 这是否意味着我必须为每个这些标签创建一个html属性? 解决方法我通常做这样的事情:public static string Label(this HtmlHelper htmlHelper,string forName,string labelText,object htmlAttributes)
{
return Label(htmlHelper,forName,labelText,new RouteValueDictionary(htmlAttributes));
}
public static string Label(this HtmlHelper htmlHelper,IDictionary<string,object> htmlAttributes)
{
// Get the id
if (htmlAttributes.ContainsKey("Id"))
{
string id = htmlAttributes["Id"] as string;
}
TagBuilder tagBuilder = new TagBuilder("label");
tagBuilder.MergeAttributes(htmlAttributes);
tagBuilder.MergeAttribute("for",true);
tagBuilder.SetInnerText(labelText);
return tagBuilder.ToString();
}
我建议您从codeplex下载ASP.NET MVC源码,并查看内置的html帮助器。 (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net – 如何删除linq到sql?
- asp.net-mvc – Url.Action映射Route属性的错误链接
- asp.net-mvc-2 – 在选择聚合时,如何处理Linq到NHibernate的
- asp.net-mvc – 在ASP.NET MVC中对ViewModels进行验证
- asp.net-mvc-3 – DTO可以嵌套DTO吗?
- asp.net-mvc – ServiceStack应该是MVC应用程序中的服务层还
- asp.net – 如何从我的网站项目中删除未使用的CSS类?
- 使用Ninject绑定WebApi过滤器属性
- asp.net – 以编程方式编辑Web.config
- asp.net – 如何使用HtmlEncode与TemplateFields,数据绑定和
推荐文章
站长推荐
热点阅读
