Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. MVC 3 Areas for code organization giving headaches

MVC 3 Areas for code organization giving headaches

Scheduled Pinned Locked Moved ASP.NET
asp-netquestioncsharpdata-structuresdebugging
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    imak
    wrote on last edited by
    #1

    Question is described by the steps below. 1.Create a new ASP.NET MVC3 Web Application using Internet Application Template. 2.Decorate HomeController class with Authorize. 3.Run the application, It basically takes you http://localhost: 51578/Account/LogOn?ReturnUrl=%2F Everything good so far. Let’s customize a couple of things in this project. 1.Add an area named “Login” in this solution and move AccountController.cs, AccountModel.cs and whole Account folder under Viewer into appropriate folder under this Area named Login. 2.Run the application now and you will get following error Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidOperationException: The view 'LogOn' or its master was not found or no view engine supports the searched locations. The following locations were searched: ~/Views/Account/LogOn.aspx ~/Views/Account/LogOn.ascx ~/Views/Shared/LogOn.aspx ~/Views/Shared/LogOn.ascx ~/Views/Account/LogOn.cshtml ~/Views/Account/LogOn.vbhtml ~/Views/Shared/LogOn.cshtml ~/Views/Shared/LogOn.vbhtml Do I need to modify anything in the web.config or in routing to make this work?

    E 1 Reply Last reply
    0
    • I imak

      Question is described by the steps below. 1.Create a new ASP.NET MVC3 Web Application using Internet Application Template. 2.Decorate HomeController class with Authorize. 3.Run the application, It basically takes you http://localhost: 51578/Account/LogOn?ReturnUrl=%2F Everything good so far. Let’s customize a couple of things in this project. 1.Add an area named “Login” in this solution and move AccountController.cs, AccountModel.cs and whole Account folder under Viewer into appropriate folder under this Area named Login. 2.Run the application now and you will get following error Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidOperationException: The view 'LogOn' or its master was not found or no view engine supports the searched locations. The following locations were searched: ~/Views/Account/LogOn.aspx ~/Views/Account/LogOn.ascx ~/Views/Shared/LogOn.aspx ~/Views/Shared/LogOn.ascx ~/Views/Account/LogOn.cshtml ~/Views/Account/LogOn.vbhtml ~/Views/Shared/LogOn.cshtml ~/Views/Shared/LogOn.vbhtml Do I need to modify anything in the web.config or in routing to make this work?

      E Offline
      E Offline
      eddieangel
      wrote on last edited by
      #2

      I am not sure if you have to change the routing or not, but I know that when I am working with a view outside the scope of the current controller I specify it as a third parameter in the link or redirect. Ex: @Html.ActionLink("Back to Claims", "Index", "Claim") Where arg 1 is the name of the link, arg 2 is the action and arg 3 is the appropriate controller. Also, if you look at the web.config file there is a forms loginUrl attribute that you can change to point to the correct login page, I imagine. Cheers, --EA

      I 1 Reply Last reply
      0
      • E eddieangel

        I am not sure if you have to change the routing or not, but I know that when I am working with a view outside the scope of the current controller I specify it as a third parameter in the link or redirect. Ex: @Html.ActionLink("Back to Claims", "Index", "Claim") Where arg 1 is the name of the link, arg 2 is the action and arg 3 is the appropriate controller. Also, if you look at the web.config file there is a forms loginUrl attribute that you can change to point to the correct login page, I imagine. Cheers, --EA

        I Offline
        I Offline
        imak
        wrote on last edited by
        #3

        I have tried changing the path in web.config for loginUrl attribute but didn't had any luck. It just keep complaining about access issues whenever I direct it outside ~\View folder. As for @Html.ActionLink, I am not sure where to force it. Because re-direction to Logon page is happening due to fact that I have decorated my HomeController with Authorize attribute and therefore there is no @Html.ActionLink involved.

        E 1 Reply Last reply
        0
        • I imak

          I have tried changing the path in web.config for loginUrl attribute but didn't had any luck. It just keep complaining about access issues whenever I direct it outside ~\View folder. As for @Html.ActionLink, I am not sure where to force it. Because re-direction to Logon page is happening due to fact that I have decorated my HomeController with Authorize attribute and therefore there is no @Html.ActionLink involved.

          E Offline
          E Offline
          eddieangel
          wrote on last edited by
          #4

          I think that from an organizational standpoint the issue is that the top level folder structure should be View - Model - Controller. Build your application and see where it places the account view that you are looking for, whether you put it somewhere else or not in the folder structure for Visual studio, when it compiles up it should end up under the deployed views folder, I think. I don't know for sure though, look and see where the deployed page lands in the folder structure in relation to the "views" folder, which is considered the "top level" folder for your web pages. Edit: Check out this link in regards to registering areas. For me it all seems a little over complicated, I prefer the classic Model - View - Controller structure with each of those items having relevant subfolders (Model - Account, View - Account, Controller - Account)

          I 1 Reply Last reply
          0
          • E eddieangel

            I think that from an organizational standpoint the issue is that the top level folder structure should be View - Model - Controller. Build your application and see where it places the account view that you are looking for, whether you put it somewhere else or not in the folder structure for Visual studio, when it compiles up it should end up under the deployed views folder, I think. I don't know for sure though, look and see where the deployed page lands in the folder structure in relation to the "views" folder, which is considered the "top level" folder for your web pages. Edit: Check out this link in regards to registering areas. For me it all seems a little over complicated, I prefer the classic Model - View - Controller structure with each of those items having relevant subfolders (Model - Account, View - Account, Controller - Account)

            I Offline
            I Offline
            imak
            wrote on last edited by
            #5

            I am not changing any organizational strucutre.If you follow my instructions from original question, everything is wherever prjoect create by default. All I am doing is that I am creating a new area, but not any custom location. Its wherever VS created by default. The only thing is that its been called by framework itself as I am just applying an attribute and not any Html.XXXX() call.

            E 1 Reply Last reply
            0
            • I imak

              I am not changing any organizational strucutre.If you follow my instructions from original question, everything is wherever prjoect create by default. All I am doing is that I am creating a new area, but not any custom location. Its wherever VS created by default. The only thing is that its been called by framework itself as I am just applying an attribute and not any Html.XXXX() call.

              E Offline
              E Offline
              eddieangel
              wrote on last edited by
              #6

              I think if you add an area you are going to have to mess around with routes. I don't know because I haven't created any areas, I just use the default View, Model and Controller folders created when you create a project using the MVC3 template in VS2010 without adding an area. To me it is still clean because when you want to generate a controller, you just generate it under the controllers folder. When you generate that controller with scaffolding it creates all of the views in a clean folder under the views folder. Just me though, if the application is going to get massive and unwieldy, maybe that is a good way to do it, but I haven't read enough about areas to see an appeal. Sorry I couldn't be more help.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups