Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6889141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:07:06+00:00 2026-05-27T06:07:06+00:00

I want to send email using old good approach of MVC 2 by converting

  • 0

I want to send email using old good approach of MVC 2 by converting code into MVC 3.
But it gives an error here:

            Control control1 = vp1.LoadControl("/Views/Home/_SupportEmailAdmin.cshtml");
            vp1.Controls.Add(control);

The error message:

Type ‘ASP._Page_Views_Home__SupportEmail_cshtml’ does not inherit from ‘System.Web.UI.UserControl’.

Is there a correct way to do it?

Here is the Code:

 ViewBag.SupportRequest = this.SupportRequest;

                    ViewPage vp1 = new ViewPage();
                    vp1.ViewData = ViewData;

                    Control control1 = vp1.LoadControl("/Views/Home/_SupportEmailAdmin.cshtml");
                    vp1.Controls.Add(control);

                    StringBuilder sb1 = new StringBuilder();
                    using (StringWriter sw1 = new StringWriter(sb1))
                    {
                        using (HtmlTextWriter tw1 = new HtmlTextWriter(sw1))
                        {
                            vp1.RenderControl(tw1);
                        }
                    }

                    sb1.Insert(0, @"<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Strict//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd""><html xmlns=""http://www.w3.org/1999/xhtml""><body>");
                    sb1.Append("</body></html>");

                    MailMessage msg1 = new MailMessage(new MailAddress(this.SupportRequest.EMail, this.SupportRequest.Name),
                        new MailAddress(from, fromName));
                    msg1.Subject = fromSubject;
                    msg1.IsBodyHtml = true;
                    msg1.Body = sb1.ToString();
                    ....

In two words the question is how to use the MVC 3 page template to render it as text and send it.

UPDATES:

The finial solution…

#region Send Support Request to Admin

                StreamReader streamReader1 = new StreamReader(Server.MapPath("/Views/Home/_SupportEmailAdmin.cshtml"));
                string emailTemplate1 = streamReader1.ReadToEnd();
                streamReader1.Close();

                string result1 = Razor.Parse(emailTemplate1, new { Name = sr.Name, EMail = sr.EMail, Subject = sr.Subject, Message = sr.Message });

                StringBuilder sb1 = new StringBuilder();
                sb1.Insert(0, @"<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Strict//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd""><html xmlns=""http://www.w3.org/1999/xhtml""><body>");
                sb1.Append(result);
                sb1.Append("</body></html>");

                MailMessage msg1 = new MailMessage(new MailAddress(sr.EMail, sr.Name),
                    new MailAddress(from, fromName));
                msg1.Subject = fromSubject;
                msg1.IsBodyHtml = true;
                msg1.Body = sb1.ToString();

                #endregion

                smtp.Send(msg1);

and the content of cshtml

file

<table>
    <tbody>
        <tr>
            <td>
                Name
            </td>
            <td>@Model.Name
            </td>
        </tr>
        <tr>
            <td>
                Email
            </td>
            <td>@Model.EMail
            </td>
        </tr>
        <tr>
            <td>
                Subject
            </td>
            <td>@Model.Subject
            </td>
        </tr>
        <tr>
            <td>
                Message
            </td>
            <td>@Model.Message
            </td>
        </tr>
    </tbody>
</table>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T06:07:06+00:00Added an answer on May 27, 2026 at 6:07 am

    Take a look at the RazorEngine project

    http://razorengine.codeplex.com/

    and maybe ready to use solution – MvcMailer

    https://github.com/smsohan/MvcMailer/wiki/MvcMailer-Step-by-Step-Guide

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to send email using php through xampp server.here is my code <?php
I am using log4net. When Application gives an error, I want to send e-mail
I want to send an email with an attachment using the following code (Python
I want to send email to Yahoo mail using Indy. But Yahoo uses 465
Here's a scenario; I want to send email using PHP and Zend Framework. Here's
I want to send email using the php code, Following is the code should
i want to write application who send email using outlook and i found this
How can I send an HTML-formatted email with pictures using PHP? I want to
I want send a email by Email Class in codeigniter with gmail, but i
I am using this code to send email var message = new MailMessage(abc@somedomain.com, administrator@anotherdomain.com);

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.