MVC自我学习

MVC自我学习:

ViewData管理传值;
<%: %> 取值;

1:HtmlHelper
  (1):超链接

//new { name = "admin", pwd = "123" }//路由参数
//new { @class="txt" }Html参数;
<%:Html.ActionLink("关于", "About", "Home", new { name = "admin", pwd = "123" },
new { @class="txt" } )%>
 
(2):DropDownList()
  List<SelectListItem> list = new List<SelectListItem>(){
             new SelectListItem(){ Text="北京", Value="1"},
             new SelectListItem(){ Text="山东", Value="2", Selected=true}
            };
  ViewData["city"] = list;//ViewData的名字与下拉框的名字一样,那么自动填充到下拉框中。

            


(3):<%: %>与<%=%>
  <%: %>:进行了HTML编码htmlEncode
  <%= %>:原样输出

  
(4):RadioButton的应用
   

2:MVCHtmlHelper扩展方法
namespace System.Web.Mvc
{
    //1:扩展方法所在的类必须是静态类
    //2:扩展方法必须是静态方法
    //3:第一个参数必须是this关键字,后面跟的是对哪个类型进行扩展(为哪个类添加的扩展方法)
    //MvcHtmlString,不会再对HTML进行编码
    public static class htmlHelperExt
    {
        public static MvcHtmlString MyLabel(this HtmlHelper helper, string txt)
        {
            //返回一个MvcHtmlString;
            //MvcHtmlString mvcstring = new MvcHtmlString(string.Format("<span style='color:red'>

{0}</span>", txt));
            //return mvcstring;  
            string temp= string.Format("<span style='color:red'>{0}</span>",txt);
            return MvcHtmlString.Create(temp);
        }
    }
}

(1):伙伴类的使用
(2):自己定义验证规则
(3):使用Jquery的Validate进行校验

    <script type="text/javascript">
        $(function () {

            $("#form1").validate({
                rules: {
                    Email: {
                        required: true,
                        email: true
                    },
                    ID: { required: true },
                    UserName: { maxlength: 5, required: true }
                   
                },
                messages: {
                    Email: "*错的邮箱",
                    ID: "*必填",
                    UserName: "*"
                    
                }
            });
        });

</script>

4:Ajax应用
  (1):基本应用
<script src="../../Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script type="text/javascript">
        $(function () {
            $("#btnGetDate").click(function () {
                $.ajax({
                    url: "/Home/GetDateNow",
                    type: "POST",
                    data: "",
                    success: function (data) {
                        $("#result").text(data);
                    }
                });

                //$.post("", "", function () { });
            });

        });
    </script>

5:MVC实现分页

  (1):基本分页完成
		       from c in db.UserInfo
                       .OrderBy(c => c.Uid)
                       .Skip<UserInfo>((pageIndex - 1) * pageSize)//跳过的页数
                       .Take<UserInfo>(pageSize)//取多少条
                       .ToList()
                       select c;
  (2):使用HtmlHelper封装分页 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值