views:

92

answers:

2

Suppose I have a dynamic html form generated by MVC view (database data with style sheet). Then I want to send the same html with email. For example, the result maybe is something like:

  <div id="DivForPrint">
        <fieldset>
            <legend>Hello</legend>
            <table>
                <tbody><tr>
                    <td>
                        <label for="ID">
                            ID&nbsp;#:</label>
                    </td>
                    <td>
                        <span class="displayData">
                            9
                        </span>
                    </td>
                    <td width="100%"></td>
                    <td>
                        <label>
                            Date:
                        </label>
                    </td>
                    <td width="100px">
                        <span class="displayData">
                            23/09/2009_2:28_PM
                        </span>
                    </td>
                </tr>
            </tbody></table>
        </fieldset>
    </div>

How to get it and send it out with email? even I can set something like mail.IsBodyHtml = true; but style sheet is not available when sending email out

+1  A: 

You are correct. Stylesheets are not available because the vast majority of e-mail clients will not load any external content other than images. If you want styled content it should be created with inline style definitions.

I just found this pretty awesome tool which will convert style definitions and related HTML into inline style definitions.

Nathan Taylor
From the sounds of it I at least partially misunderstood your question, hopefully my answer was still useful. :)
Nathan Taylor
+1  A: 

I'm pretty sure you can get the output of a View by calling the ViewResult's View.Render() method and then looking at the text writer that was passed in.

This is totally just me hypothesizing though.

Dusda
If that does in fact work you could get creative and build a service to replicate the tool I linked above then concatenate the HTML response from your View with it's linked stylesheet (or local style- whichever) and send the whole string to the service for "inline-style-ification". That way you could continue to use your linked styles and simply build inline styled e-mails completely on the fly. That would be pretty cool to see!
Nathan Taylor
Yea it would. I'm really busy right now, but I've actually thought about using Views to render html for emails (it will likely be a 'thing' in the next project I'm working on). I'll throw up some sample code on this when I get around to tackling that problem.
Dusda