Fatih Erol
Fatih Erol

Reputation: 699

Asp.net Mvc Controller return optional view

I'm new Asp.net Mvc I have one Controller and Two View.

Controller -HomeController

View -ProfileView -PageView

I must return ProfileView or PageView

My codes are working but I can not be sure this is the right approach.

This my code

        if (Username == "Fatih")
        {
            return View("ProfileView");

        }
        else
        {
            return View("PageView");
        }

Upvotes: 0

Views: 94

Answers (1)

CoderM
CoderM

Reputation: 81

There is nothing wrong with your approach. The else block is not needed.just have the second return below the if block.

Upvotes: 1

Related Questions