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>

Advertisements

Tags: , , ,

About Eric

My name is Eric Weintraub. I am an IT Professional with over 12 years of real world experience. I currently work as a Senior IT Manager for a large software company that develops products for Information Technology workers. Professionally, I love what I do and it shows in my work. Personally, I enjoy technology as a whole. Enterprise Technology, Social Media, and Mobile technologies are all things I follow. I also love to play golf, go snowboarding, cook, love to eat, and read. Also big on photography, check out my recent photography at http://www.ericweintraubphotography.com and also Flickr: http://www.flickr.com/photos/ericweintraub/. As much as I don’t have a lot of free time, I always come across things that I believe could help others. I just wanted to be able to share what I find with others. Thanks for reading the blog, please setup a RSS feed and keep in touch! Eric Weintraub

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: