locked
Help organizing code. RRS feed

  • Question

  • User-1618960079 posted

    I am developing a web site and one of my admin pages has about 1000 lines of C# code at the beginning of the page.  It has become a little unwieldy and I would like to somehow organize it better.  I have tried putting the code into separate cshtml files and calling them using RenderPage.  But some of the code doesn't seem to work when I do this.  Please don't tell me I need to go to MVC because Web Pages and Webmatrix aren't designed for that kind of complexity.  Because that will make me cry.

    Thursday, July 9, 2015 11:59 PM

Answers

All replies

  • User-821857111 posted

    Try shifting some of the code into functions: http://www.mikesdotnetting.com/article/173/the-difference-between-helpers-and-functions-in-webmatrix. That way you can replace blocks of code with single function calls, and it makes your code more reusable.

    Please don't tell me I need to go to MVC because Web Pages and Webmatrix aren't designed for that kind of complexity.
    Anyone who suggests that doesn't know what they are talking about.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, July 10, 2015 2:00 AM
  • User379720387 posted

    I have some experience with large swaths of code on a single page reaching the point where it becomes too difficult to keep an overview.

    Breaking it up in smaller pages bring complexity too, plus the overhead of extra queries needed to continue the code from the next page.

    Also, if you ever decide to use Entity Framework you will regret those different pages.

    Last, don't use WebMatrix, but use Visual Studio for working on your code, and keep WebMatrix in a separate window for the db work.

    VS has many more capabilities to deal elegantly with large pages.

    MVC? 

    MVC adds so many complexities by itself, that you gladly deal with 10,000 lines of code in WebMatrix.

    Friday, July 10, 2015 8:37 AM
  • User-1618960079 posted

    Thanks guys, for the quick response and great ideas.

    Friday, July 10, 2015 11:07 PM