VS2010 MVC HtmlHelper的使用

        <!--
            给Action传递参数


            在控制器中按如下代码定义Action


            public ActionResult MyActionParam(int Age)
            {
                return Content(Age.ToString());
            }
        -->

        <%= Html.ActionLink("提交参数给Action方法","MyActionParam",new {Age=35}) %>


        <!--定位到指定的Controler-->
        <%= Html.ActionLink("定位到Limin控制器下的Index视图","Index","Limin",new {MsgInfo="北京欢迎你!"},null) %>


        <!--%:和%=的区别-->
        <!--在控制器中加入ViewData["MySpan"] = "<span>我是Span</span>";-->

        <%: ViewData["MySpan"] %>
        <%= ViewData["MySpan"] %>




        <!--测试RadioButton-->
        <fieldset style="width:160px;">
            <legend>请选择性别</legend>
            男:<%: Html.RadioButton("Gender","Female",true) %>&nbsp;
            女:<%: Html.RadioButton("Gender","Female",false) %>&nbsp;
            男或女:<%: Html.RadioButton("Gender","Female",false) %>
        </fieldset>


        <!--演示DropdownList下拉框-->
        <!--
            在控制器中加入如下代码:
            ViewData["DDLData"] = new List<SelectListItem>(){
                new SelectListItem(){Selected=true,Text="南昌",Value="1"},
                new SelectListItem(){Selected=false,Text="北京",Value="2"},
                new SelectListItem(){Selected=false,Text="上海",Value="3"},
                new SelectListItem(){Selected=false,Text="武汉",Value="4"}
            };


            需要注意ViewData["DDLData"]中的DDLData要和视图中的
            Html.DropDownList("DDLData")的名字一样,这样才能进行装配
        -->

        <%: Html.DropDownList("DDLData") %>




        <!--演示HtmlHelper扩展方法
        
            添加一个类,代码如下:
            //该类演示了扩展HtmlHelper的方法
            //扩展类方法必须满足的条件
            //1.MyHtmlHelper必须为静态类
            //2.MyLabel方法必须为静态方法
            public static class MyHtmlHelper
            {
                public static string MyLabel(this HtmlHelper helper, string label)
                {
                    return string.Format("<span>{0}</span>", label);
                }
            }
        -->



        <%: Html.MyLabel("我扩展的Label,自动生成Span标签") %>

你可能感兴趣的:(VS2010 MVC HtmlHelper的使用)