質問

これが私の現在のコードです、私はこれを使用してタブを実装しています

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;
    }
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top