mvc 小计

来源:互联网 发布:武汉软件培训 编辑:程序博客网 时间:2024/05/29 16:17

使用mvc 小计

1.关于页面{
[mvcapplication模式]
csthml=”需要一个新的control类对应否则访问会找不到(为什么会这样呢 因为每个页面的呈现都需要经过control类的逻辑处理)”,
“RenderPatial RenderAction 区别 “=”RenderPatial的数据来自于调用的View,而RenderAction来自自己。[取于其他人总结]”,
“RenderPatial RenderAction 区别 “=”RenderAction会发起一个新的Request,而RenderPatial不会。[取于其他人总结
详情参考 csdn死对头
http://www.cnblogs.com/gesenkof99/archive/2013/06/03/3115052.html
]”,
}

2.关于页面控件{
[呈现html控件]
@Html.LabelFor(m => m.name) = “显示[Display] 的内容”,
@Html.Label(m => m.mypwd)=“显示model属性的值”,
@Html.ValidationMessageFor(m=>m.name) =”如果要显示验证信息需要加上这个”,
}

3.关于控制{
身份
[AllowAnonymous] =”身份验证需要配置web.config[



]”,
自定义验证=”重写ActionFilterAttribute[

public class IsLogin : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
bool isLogin = false;

        //用MVC系统自带的功能 获取当前方法上的特性名称        bool skipAuthorization = filterContext.ActionDescriptor.IsDefined(typeof(NoNeedLogin), inherit: true)                                 || filterContext.ActionDescriptor.ControllerDescriptor.IsDefined(typeof(NoNeedLogin), inherit: true);        if (skipAuthorization)        {            return;        }        //检查是否登录        AdminBll adminBll = new AdminBll();        if (!adminBll.IsLogin())        {            //强制调转实现身份验证            filterContext.HttpContext.Response.Redirect("http://" + filterContext.HttpContext.Request.Url.Authority + "/Admin/Login");        }    }} //忽略身份验证 public class NoNeedLogin : Attribute{ } //验证 [IsLogin]public class AdminController : BaseController{    //登录 表单(忽略验证)    [NoNeedLogin]    public ActionResult Login()    {        return View();    }

]”

}

0 0
原创粉丝点击