C# Razor | Dump Request.Form Data to Table

So I have recently been weaning myself off ColdFusion to another coding language. I am really liking what I am seeing in C# Razor tags. It has the same general workflow as Coldfusion without the need for an expensive application server.

Anyways in Coldfusion there was <cfdump var=#VarName#> which would spit out a wonderful  table of all the variable elements.  I was dumbstruck to find out there is no such native functionality in C# / C# Razor.

I wrote this to do the exact same thing. Enjoy! 

@{int i = 0;}
    <table>
        <tr>
            <td>Index</td>
            <td>Field Name</td>
            <td>Field Data</td>
        </tr>
    @foreach (var fd in Request.Form.AllKeys) {
        <tr>
            <td>@i</td>
            <td>@fd</td>
            <td>@Request.Form[fd]</td>
        </tr>
    i++;
        }

    </table>

Leave a Reply

Your email address will not be published. Required fields are marked *