Click here to Skip to main content
15,891,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am developing an MVC application to allow user to register/create and login. On my view folder, under ViewStart.cshtml there is an execption below and dont know how to fix this please assist mates "Value cannot be null, parameter name- virtualPath".

What I have tried:

C#
<pre>@{
    var controller = HttpContext.Current.Request.RequestContext.RouteData.Values["Controller"].ToString();

    string layout = "";
    if(controller == "Admin")
    {
        Layout = "~/Views/Shared/_Layout.cshtml";

    }else
    {
         Layout = "~/Views/Shared/_MainLayout.cshtml";
    }
    Layout = layout;
 
}
Posted
Updated 20-Jan-20 21:47pm

1 solution

If you debug your code you will find out that you set Layout depending on the controller configuration.
So far so good.
Then you replace Layout with layout which was set to an empty string before.
Please try this:
@{
    var controller = HttpContext.Current.Request.RequestContext.RouteData.Values["Controller"].ToString();

    if(controller == "Admin")
    {
        Layout = "~/Views/Shared/_Layout.cshtml";

    }else
    {
        Layout = "~/Views/Shared/_Layout.cshtml";
    }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900