zoukankan      html  css  js  c++  java
  • 主攻ASP.NET MVC4.0之重生:使用反射获取Controller的ActionResult

    示例代码

            public ActionResult TypeOfForName()
            {
                Type typeinfo = typeof(CustomerClassController);
                //typeof获取Controller系统原型对象
                string strinfo = "";
    
                MethodInfo[] methodinfo = typeinfo.GetMethods();
                foreach (MethodInfo minfo in methodinfo)
                {
                    string tempstr = Reg(@"System.Web.Mvc.ActionResult(.*)((.*))", minfo.ToString(), 1);
                    strinfo += "<div class="span9"><div id="data-list">" + tempstr + "</div></div>";
                }
    
                ViewBag.ActionResultStr = strinfo;
    
                return View(list);
                
            }
            public static string Reg(string regexstr, string codestr, int index)
            {
                Regex VIEWSTATERegex = new Regex(regexstr);
                MatchCollection VIEWSTATEMatchResult = VIEWSTATERegex.Matches(codestr);
                string regstr = "";
                foreach (Match vmr in VIEWSTATEMatchResult)
                {
                    regstr = vmr.Groups[index].Value.ToString();
                }
                return regstr;
            }
    

    typeof获取Controller系统原型对象

    代码运行结果

    Index

    Search

    Add
    Add
    Edit
    Edit
    Detail
    Delete
    Delete
     
     

     声明:本博客高度重视知识产权保护,发现本博客发布的信息包含有侵犯其著作权的链接内容时,请联系我,我将第一时间做相应处理,联系邮箱ffgign@qq.com


    作者:Mark Fan (小念头)    
    来源:http://cube.cnblogs.com
    说明:未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。如有疑问,可以通过 ffgign@qq.com 联系作者,本文章采用 知识共享署名-非商业性使用-相同方式共享 2.5 中国大陆许可协议进行许可

    知识共享许可协议

     
  • 相关阅读:
    vuex插件
    axios
    token登录验证
    mysql模糊查询
    Koa2+Mysql搭建简易博客
    正则匹配器
    编码
    Maven学习
    防止重复提交保证幂等的几种解决方案
    策略模式优化if-else
  • 原文地址:https://www.cnblogs.com/cube/p/3448233.html
Copyright © 2011-2022 走看看