2011-03-16 18 views
0

这里是我当前的代码,我用这来实现标签如何从控制器上下文返回的ActionResult的另一个动作

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

回答

0

这是我目前的起飞,这看起来不自然的我

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; 
    } 
相关问题