【问题标题】:how to create custom route in mvc4如何在 mvc4 中创建自定义路由
【发布时间】:2019-01-12 03:07:12
【问题描述】:

我想在 RedirectToAction 之后喜欢这个 (/User/Index?abc) url
怎么做请给我建议..

RouteConfig.cs

routes.MapRoute(
   name: "Putabc",
   url: "{tempUrl}/{RegNo}",
   defaults: new { controller = "User", action = "Index", RegNo = UrlParameter.Optional}
);

控制器:-

public ActionResult Putabc() 
{ 
    string RegNo = "abc"; 
     string tempUrl = Url.Action("Index", "User");
    return RedirectToAction(new { url = tempUrl + "?{RegNo}" }, JsonRequestBehavior.AllowGet);
}  

【问题讨论】:

    标签: c# asp.net-mvc-4 routes


    【解决方案1】:

    请试试这个

    RouteConfig 内部

         routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );
    

    //注意:这里的“Home”和“Index”是你的默认控制器和动作

    控制器

     [RoutePrefix("User")]
    
    public class SomeController : Controller
    {  
     //This action will be hit by 
    
     // www.yoursite.com/User/Index?url=some
       public ActionResult Index(string url) 
       { 
    
       }  
    }
    

    HomeController

    public class HomeController : Controller
    { 
       public ActionResult Putabc() 
      { 
         string RegNo = "abc"; 
         string tempUrl = Url.Action("Index", "User");
          return RedirectToAction(new { url = tempUrl + "?{RegNo}" }, 
         JsonRequestBehavior.AllowGet);
      }  
    }
    

    【讨论】:

      猜你喜欢
      • 2014-03-30
      • 2013-03-13
      • 1970-01-01
      • 1970-01-01
      • 2016-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多