代码改变世界

MVC HTML控件扩展例子

2012-08-31 14:15  yuxianghappy  阅读(190)  评论(0编辑  收藏  举报
 1  public class MyControls    {       
 2  /// <summary>      
 3  /// Lable文本        
 4 /// </summary>        
 5 /// <param name="fortarget">for属性</param>        
 6 /// <param name="text">显示文本</param>       
 7  /// <returns></returns>        
 8 public static MvcHtmlString Label(string fortarget, string text)       
 9  {            
10 string str = String.Format("<label for='{0}'>{1}</label>", fortarget, text);           
11  return new MvcHtmlString(str);                    
12 }       
13  public static MvcHtmlString Label(string text)        {            return Label("",text);        }      
14   /// <summary>        
15 /// RadioButton       
16  /// </summary>        
17 /// <param name="nametarget">name属性</param>        
18 /// <param name="idtarget">id属性</param>        
19 /// <returns></returns>       
20  public static MvcHtmlString RadioButton(string nametarget, string idtarget)        
21 {            
22 string str = String.Format("<input type='radio' name='{0}' id='{1}' />", nametarget, idtarget);           
23  return new MvcHtmlString(str);        
24 }   
25  }