HiveBrain v1.2.0
Get Started
← Back to all entries
patterncsharpMinor

Make huge view in C# readable and maintanable

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
readablemakeviewhugeandmaintanable

Problem

I have an application that is using MVC5 with C# and Razor Engine. This view displays a huge table:




Actions
Order Status
Order Details
Order Date
Expected Delivery Date
Ordered By
Employee ID
Employee Status
Employee Name
Employee Type
Scope
Delivery Address
Comment










Now, the problem is that everything is in one huge file. As you can guess, this file is a nightmare to update and maintain.

I am familiar with the C# region directive, but I can't find anything similar for Views. I also know about partial views, but I have the strong impression from discussions in Stack Overflow that these should only be used when I have a piece of code in a View that is re-usable, which is not the case.

What is the best way to deal with Views this large?

Solution

I would use a Partial View for this code.
Anytime I have a menu for a page I put it in a partial view even though it may not be used on another page.

@Html.Partial("_Actions")
@Html.Partial("_OrderStatus")
@Html.Partial("_OrderDetails")
@Html.Partial("_OrderDate")


inside the Partial view placed in Views/Shared

@model ActionsViewModel
Column 1 
Column 2 
Column 3 
Column 4 
Column 5


etc...
Good Luck!

Code Snippets

<tr>@Html.Partial("_Actions")</tr>
<tr>@Html.Partial("_OrderStatus")</tr>
<tr>@Html.Partial("_OrderDetails")</tr>
<tr>@Html.Partial("_OrderDate")</tr>
@model ActionsViewModel
<td>Column 1</td> 
<td>Column 2</td> 
<td>Column 3</td> 
<td>Column 4</td> 
<td>Column 5</td>

Context

StackExchange Code Review Q#71552, answer score: 4

Revisions (0)

No revisions yet.