• 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);
  • 相关阅读:
    hdu2328 Corporate Identity
    hdu1238 Substrings
    hdu4300 Clairewd’s message
    hdu3336 Count the string
    hdu2597 Simpsons’ Hidden Talents
    poj3080 Blue Jeans
    poj2752 Seek the Name, Seek the Fame
    poj2406 Power Strings
    hust1010 The Minimum Length
    hdu1358 Period
  • 原文地址:https://www.cnblogs.com/zhuji/p/8072049.html
Copyright © 2020-2023  润新知