Asp.net 如何从控制器上下文返回另一个操作的actionresult
这是我当前的代码,我用它来实现标签Asp.net 如何从控制器上下文返回另一个操作的actionresult,asp.net,asp.net-mvc-2,actionresult,renderaction,Asp.net,Asp.net Mvc 2,Actionresult,Renderaction,这是我当前的代码,我用它来实现标签 public ActionResult Index(string tabs, int id = 0) { switch ((Tabs)Enum.Parse(typeof(Tabs), tabs,true)) { case Tabs.Profile: default: return Profile(id); } } public ActionResult Profile(int
public ActionResult Index(string tabs, int id = 0)
{
switch ((Tabs)Enum.Parse(typeof(Tabs), tabs,true))
{
case Tabs.Profile:
default:
return Profile(id);
}
}
public ActionResult Profile(int id = 0)
{
User user = UsersRepository.GetUser(id);
if (user!= null)
{
return View(user);
}
return Redirect("/");
}
我不想使用RedirectToAction
,因为这会改变我想要的URL结构。大概是这样的:
http://localhost/user?tabs=profile
http://localhost/user?tabs=settings
这是我目前的想法,我觉得这很不自然
public ActionResult Index(string tabs, int id = 0)
{
switch ((Tabs)Enum.Parse(typeof(Tabs), tabs,true))
{
case Tabs.Profile:
default:
var userProfile= Profile(id);
if (userProfile!= null)
{
return View("Profile",userProfile);
}
return Redirect("/");
}
}
[NonAction]
public UsersViewModel Profile(int id = 0)
{
UsersViewModel user= UsersRepository.GetUser(id);
return user;
}