主攻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 中国大陆许可协议进行许可

知识共享许可协议

 

 

转载于:https://www.cnblogs.com/cube/p/3448233.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值