3

If you have created a controller like:

public class ProjectLoginController : Controller
{
    /// <summary>
    /// GET: /login
    /// </summary>
    /// <returns></returns>
    [HttpGet]
    [AllowAnonymous]
    public ActionResult Login()
    {
        return View();
    }
}

It will search for the login view in the ProjectLogin or the Shared folder.

Is it possible to tell MVC for this controller to search in the views folder Account under Viewsinstead of doing:

return View("~/Views/Account/Login.cshtml");

or:

return View("../Account/Login");
5
  • You can do like this, return View("../Account/Login", yourModel ); Commented Jul 5, 2017 at 7:55
  • But is there no attribute you can set with the default views folder to search in for this particular controller? Commented Jul 5, 2017 at 7:56
  • 1
    check this stackoverflow.com/questions/632964/… Commented Jul 5, 2017 at 9:16
  • @Mivaweb I have the same problem. I need to do this for a single controller. Did you find a solution? Commented Sep 13, 2023 at 17:57
  • @MartinD. seems a long time ago, but I remember that the link of Krishna was helpfull. Commented Sep 14, 2023 at 7:02

2 Answers 2

2

You can use RedirectToAction() method for this. For example,

return RedirectToAction("LogIn", "Account");

Or-else, do like this,

return View("../Account/Login");

Hoe it helps :)

Sign up to request clarification or add additional context in comments.

Comments

0

Yes you can do this by following ways:

return View("../Account/Login");

or

return RedirectToAction("LogIn", "Account");

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.