MVC View that will display attributes of any Model

So I spend a lot of time creating simple internal apps that aren't pretty, but are great for giving people (me) access to data without query analyzer, very simple apps in short.  I hate it when I have to update these simple apps though, and if you create enough of them, objects in the system are always changing and you end up wasting a lot of time updating views to show the new data.  
To help this, I devised a bit of code to put in your view that will render a model for ever, updating even if the object changes.  Lets check it out.
<div class="fieldgrid" style="float:left;">
            <table class=" table-bordered" style="max-width:200px;word-wrap: break-word;">
                @{int i = 20; }
                @foreach (var prop in Model.GetType().GetProperties().Where(c => !c.PropertyType.ToString().Contains("Collections.Generic")).OrderBy(c => c.Name))
                {
                    if (i == 0)
                    {
                        i = 20;
                        @:</table></div>
                    @:<div class="fieldgrid" style="float:left;"><table class=" table-bordered" style="max-width:200px;word-wrap: break-word;">
                }
                    <text>
                        <tr>
                            <td class="display-label">
                                @prop.Name
                            </td>
                            <td>
                                @prop.GetValue(Model, null)
                            </td>
                        </tr>
                    </text>
                    i--;
                }
            </table>
        </div>
So whats going on isn't pretty, but basically I am reflecting my model, and the looping through its properties and displaying them in alphabetical order.  I also try to weed out the complex types in the where clause as you can see.  This did get a bit more complex because I wanted to split them into smaller tables so they don't get too huge, that's where the if block comes in.  But really, a rather simple, and powerful way to display a model dynamically.

Nested If and For loops in views woes

I want to start this off by saying that I generally don't like using C# code in my views, I feel it is bad practice.  I would much rather the models be simple enough to be displayed without the use of code on the front end.  I also feel that display views for complex nested types should be used as partial views, this is the correct way to do it in my opinion.  However, situations arise where you can't refactor all your models to work, or it isn't worth it.  For these cases, it is often better to simply break down and put the if and for blocks in the view.  This does have some syntax challenges I will talk through.  
The first is the @ symbol.  You are probably familiar with using it before all calls to the Html Helper and such.  Now if we have an if block, that if block must be started with an @ and then it will have { curleys } around stuff that occurs on that condition.  This works well enough if you just have html in there.  But lets say you have 2 nested if blocks, well you have to be careful now.  
Basically, after you have an @, it is code until it sees what it thinks is static text, usually an html tag.  Sometimes it isn't so easy for the parser to figure this out.  So say you have 2 if blocks in a row, well it is going to be upset.  This is where the @: syntax and the <text></text> syntax come into play.  Basically, in complex scenarios like this (nested) we need to specify everything that is text so it can know the rest is code and parse correctly.  Here is what my double if looks like in a for loop for reference using the above syntax.
<div class="fieldgrid" style="float:left;">
            <table class=" table-bordered" style="max-width:200px;word-wrap: break-word;">
                @{int i = 20; }
                @foreach (var prop in Model.GetType().GetProperties().Where(c => !c.PropertyType.ToString().Contains("Collections.Generic")).OrderBy(c => c.Name))
                {
                    if (i == 0)
                    {
                        i = 20;
                        @:</table></div>
                    @:<div class="fieldgrid" style="float:left;"><table class=" table-bordered" style="max-width:200px;word-wrap: break-word;">
                }
                    <text>
                        <tr>
                            <td class="display-label">
                                @prop.Name
                            </td>
                            <td>
                                @prop.GetValue(Model, null)
                            </td>
                        </tr>
                    </text>
                    i--;
                }
            </table>
        </div>
So this code I will talk about in another post, but for the scope of this post, it creates many tables from a set of data.  It does a simple for loop of the data to do so, but breaks the table into 20 record chunks.  So a counter is created and an if block put in place to see if the counter hits 0, it resets the counter and ends and starts a new table.  The static text is all identified either with a @: before it, or surrounded in <text></text> tags.  I would have only used <text> tags, however, wrapping just closing tags with it doesn't go well as precompiler xml is hard to differentiate from post xml I guess.  But this works and is how to do such things.  
Remember, just because you can, doesn't mean you should.

Downloading a CSV file from MVC Controller

So I had a request from a user on an app to download a CSV file from my MVC web site.  I had previously showed how to upload a csv to MVC, so this shouldn't be hard.  The first thing you need to do is create a function on your controller to put the file together and return it.  Here is a really simple example.  
    public FileContentResult DownloadCSV()
    {
        string csv = "Charlie, Chaplin, Chuckles";
        return File(new System.Text.UTF8Encoding().GetBytes(csv), "text/csv", "Report123.csv");
    }
Since CSV is just a text file, I put together a really simple one there to get the idea across.  All that is special about this function is that it returns a FileContentResult vs ActionResult (though that probably would be fine) and return a File.  That was reason.  Now the link http://site/App/controller/DownloadCSV should return a file.  You just need to create a link in your front end and done.  
If you want to do all of this from a JQuery call, it would look something like this.

$.ajax({
    type: 'POST',
    url: '/Controller/DownloadCSV', 
    data: '{  }',
    contentType: 'application/json; charset=utf-8',
    dataType: 'json',
    success: function (returnValue) {
        window.location = '/Reports/Download?file=' + returnValue;
    }
});