Wie kann man ActionResult einer anderen Aktion aus dem Controller -Kontext zurückgeben
-
24-10-2019 - |
Frage
Hier ist mein aktueller Code, ich verwende dies, um Registerkarten zu implementieren
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("/");
}
Ich möchte nicht benutzen RedirectToAction
Da wird die URL -Struktur dessen verändern, was ich wollte. Etwas wie das:
http://localhost/user?tabs=profile
http://localhost/user?tabs=settings
Lösung
Hier ist meine aktuelle Einstellung, das sieht für mich unnatürlich aus
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;
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow