我想在RedirectToAction之后喜欢这个(/ User / Index?abc)网址
怎么做请给我建议。
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);
}
答案 0 :(得分:0)
请尝试这个
内部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);
}
}