Pergunta

Here is my current code, I am using this to implement tabs

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("/");

}

I don't want to use RedirectToAction as that will change the URL structure of what I wanted. Something like this:

http://localhost/user?tabs=profile

http://localhost/user?tabs=settings

Foi útil?

Solução

Here is my current take, This looks unnatural to me

    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;
    }
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top