zoukankan      html  css  js  c++  java
  • MVC不用302跳转Action,内部跳转

    原理,在一个Action里面return 另一个Action出去。

     public class HomeController : Controller
        {
            // GET: Home
            public ActionResult Index(int? id)
            {
               //必须要把Route里的Action改成最终的Action名字,否则造成读取CSHTML错误
                ControllerContext.RouteData.Values["Action"] = "TS";
                return TS(id);
                //如果不确定到哪个Action,可以使用反射的方式来跳转
                //return this.GetType().GetMethod("TS").Invoke(this,new object[]{id}) as ActionResult;
                 
                
            }
            public ActionResult TS(int? id)
            {
                ViewBag.Id = id;
                return View();
            }
        }

     如果连控制器也不确定,可以这么写

      ControllerContext.RouteData.Values["Action"] = "Index";
                ControllerContext.RouteData.Values["Controller"] = "Test";
                Type type = Assembly.GetExecutingAssembly().DefinedTypes.Where(t => t.Name == "TestController").FirstOrDefault();
                object obj = Assembly.GetExecutingAssembly().CreateInstance(type.FullName);
                return obj.GetType().GetMethod("Index").Invoke(obj, null) as ActionResult;
  • 相关阅读:
    通过梯度下降和logistic回归求w向量和b
    一个节点的神经网络的工作流程
    对神经网络大致框架的理解
    内置对象
    对象
    预解析
    作用域
    函数
    数组
    循环和代码规范
  • 原文地址:https://www.cnblogs.com/xdoudou/p/4351140.html
Copyright © 2011-2022 走看看