深入讲解View

ViewBag,ViewData,TempData区别?

ViewBag 和 ViewData 数据"共享",作用域为 当前 Action。

TempData 作用域跨 Action。


ViewBag是一个dynamic类型集合,可以动态添加任意类型的任意名称 的 属性 和 值


View中的弱类型ViewData ["”]
Controller中设置 ViewData["msg"]   ;View中使用  @ViewData["msg"]

View中的强类型 ViewData.Model
Controller中设置 return View(user)  ;View中使用  @Model.Name  (需要@model MVCDemo.Models.Users)

mvc3、mvc4中@  相当于mvc2中<%:%>  相当于<%=Html.Encode ()%>
@(gender==true ? "男" : "女" )

客户端验证
JQuery Ajax
    $(function () {
        $("#btnGetDate").click(function () {
            $.ajax({
                url: "/Student/GetDateNow",
                type: "POST",
                data: "",
                success: function (date) {
                    alert(date);
                    $("#hehh").val(date);
                }
            });
        });
    });

在使用 Json 返回 JsonResult 时注意要将第二个参数设置允许 Get 提交方式: return Json ( "" , JsonRequestBehavior.AllowGet )
Aspnet MVC Microsoft Ajax
@using (Ajax.BeginForm("GetDateNow", new AjaxOptions { HttpMethod = "Post", InsertionMode = InsertionMode.Replace, OnSuccess = "ShowYesz", UpdateTargetId = "resultDiv" }))
{
    <div id='resultDiv'>dd</div>
    <input type="text" id="microsfotAjax" />
    <input type="submit" value="提交" />
}
AjaxOptions属性说明:
http://msdn.microsoft.com/zh-cn/library/system.web.mvc.ajax.ajaxoptions<28v=vs.108>29.aspx



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值