zoukankan      html  css  js  c++  java
  • ASP.NET MVC Controller 编程所涉及到的常用属性成员

    Controller (System.Web.Mvc.Controller)

    1.获取路由中的各个值

    Request.RequestContext.RouteData.Values["id"]

    1).参考:System.Web.Mvc.Controller > Controller类 > 它的属性

    2.相关参考:  在cs代码中获取controller或action 值 

    //定义自己的HTML助手方法
    public static string IsActiveLi(this HtmlHelper html, string roleCode = null,string cssClass = null)
    {
        string currentController = (string)html.ViewContext.RouteData.Values["controller"];
        var curActionName = (string)html.ViewContext.RouteData.Values["action"];
        //

    3.如果action是 [ChildActionOnly]  即

    @{Html.RenderAction("GenreMenu", "Store");}

    我们需要在子controller和action拿到parent controller和action 上面的代码做调整

    string currentController = (string)html.ViewContext.ParentActionViewContext.RouteData.Values["controller"]; //被ChildActionOnly调用
    var curActionName = (string)html.ViewContext.ParentActionViewContext.RouteData.Values["action"];

    stackoverflow参考

    4.Get Current Area Name in View or Controller   参考

    object area;
    Request.RequestContext.RouteData.DataTokens.TryGetValue("area", out area);
  • 相关阅读:
    XSS
    XSS
    检查空引用
    LockInt
    Unity Shaderlab: Object Outlines 转
    git 恢复单个文件的历史版本
    烽火HG220G-U E00L2.03M2000光猫改桥接教程
    mark mem
    转 class和struct最本质的区别
    unity shader base pass and additional pass
  • 原文地址:https://www.cnblogs.com/zhuji/p/8072049.html
Copyright © 2011-2022 走看看