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 6133845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:16:50+00:00 2026-05-23T17:16:50+00:00

I don’t know if I am explaining this correctly, or if the solution is

  • 0

I don’t know if I am explaining this correctly, or if the solution is rather simple, so here goes:

I am using MvcMailer, but before that I set up a wizard input form which I call Quote.cshtml. Behind Quote.cshtml, I set up a model called QuoteModel.cs.

Quote.cshtml at its most basic (I am leaving out all of the wizard logic and only showing one input):

<td width="40%">
    @Html.LabelFor(m => m.FirstName, new { @class = "mylabelstyle", title = "Enter first name." })
</td>
<td width="60%">
    @Html.TextBoxFor(m => m.FirstName)
    @Html.ValidationMessageFor(m => m.FirstName)
</td>

QuoteModel.cs (again, only showing the one input; n.b.: using the DataAnnotationExtensions)

public class QuoteModel
{ 
    [Required(ErrorMessage = "First Name required.")]
    [Display(Name = "First Name:")]
    public string FirstName { get; set; }
}

Now I am trying to integrate MvcMailer, which sets up IQuoteMailer.cs, QuoteMailer.cs, _Layout.cshtml, and QuoteMail.cshtml. The QuoteMail.cshtml is what the recipient of the mail will eventually see. I also set up a QuoteController.cs, in which I placed the appropriate code required by MvcMailer. It is in the QuoteMailer.cs and QuoteController.cs where I am having trouble passing the user input from Quote.cshtml (which is based on the model in QuoteModel.cs).

IQuoteMailer.cs:

 public interface IQuoteMailer
    {               
         MailMessage QuoteMail();
    }

QuoteMailer.cs:

public class QuoteMailer : MailerBase, IQuoteMailer     
{
    public QuoteMailer():
        base()
    {
        MasterName="_Layout";
    }


    public virtual MailMessage QuoteMail()
    {
        var mailMessage = new MailMessage{Subject = "QuoteMail"};

        mailMessage.To.Add("some-email@example.com");
        ViewBag.Data = someObject; 
                    //I imagine this is where I can pass my model, 
                    //but I am not sure (do I have to iterate each and
                    //every input (there are like 20 in QuoteModel.cs)?

                return mailMessage;
    }

QuoteMail.cshtml (_Layout.cshtml is pretty standard, so not showing here):

@*HTML View for QuoteMailer#QuoteMail*@

Welcome to MvcMailer and enjoy your time!<br />
<div class="mailer_entry">
    <div class="mailer_entry_box">
        <div class="mailer_entry_text">
            <h2>
                INSERT_TITLE
            </h2>
            <p>
                INSERT_CONTENT
                //I believe I am going to use a "@" command like @ViewData
                //to pass FirstName, but again, not sure how to bind 
                //the model and then pass it.
            </p>
            <p>
                INSERT_CONTENT
            </p>
        </div>
    </div>
</div>

And finally, the relevant parts of the QuoteController.cs (note that I have am using a wizard, therefore, part of my problem is figuring out where to put the MvcMailer code, but I think I may have it right):

public class QuoteController: Controller
{

    /// <summary>
    /// MvcMailer
    /// </summary>
    private IQuoteMailer _quoteMailer = new QuoteMailer();
    public IQuoteMailer QuoteMailer
    {
        get { return _quoteMailer; }
        set { _quoteMailer = value; }
    }

    //
    // GET: /Quote/
    [HttpGet]
    public ActionResult Quote()
    {
        HtmlHelper.ClientValidationEnabled = true;
        HtmlHelper.UnobtrusiveJavaScriptEnabled = true;
        //In order to get the clientside validation (unobtrusive), 
        //the above lines are necessary (where action takes place)
        return View();
    }

    //
    // POST: /Matrimonial/
    [HttpPost]
    public ActionResult Quote(QuoteModel FinishedQuote)
    {
        if (ModelState.IsValid)
        {
            QuoteMailer.QuoteMail().Send();
            return View("QuoteMailSuccess", FinishedQuote);
        }
        else return View();
    }

    //
    // POST: /Matrimonial/Confirm
    [HttpPost]
    public ActionResult QuoteMailConfirm(QuoteModel FinishedQuote)
    {
        return PartialView(FinishedQuote);
    }

}

So, my confusion is to how to pass the QuoteModel I created, so that ultimately I can take the user inputed data and then generate the MvcMailer view.

I appreciate the communities help.

  • 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-23T17:16:50+00:00Added an answer on May 23, 2026 at 5:16 pm

    You could have the IQuoteMailer interface take the model:

    public interface IQuoteMailer
    {
        MailMessage QuoteMail(QuoteModel model);
    }
    

    and in the implementation use this model:

    public class QuoteMailer : MailerBase, IQuoteMailer
    {
        public QuoteMailer() : base()
        {
            MasterName = "_Layout";
        }
    
    
        public virtual MailMessage QuoteMail(QuoteModel model)
        {
            var mailMessage = new MailMessage
            {
                Subject = "QuoteMail"
            };
            mailMessage.To.Add("some-email@example.com");
    
            // Use a strongly typed model
            ViewData = new ViewDataDictionary(model);
            PopulateBody(mailMessage, "QuoteMail", null);
            return mailMessage;
        }
    }
    

    then from the controller when you decide to send the mail pass the model:

    [HttpPost]
    public ActionResult Quote(QuoteModel FinishedQuote)
    {
        if (ModelState.IsValid)
        {
            QuoteMailer.QuoteMail(FinishedQuote).Send();
            return View("QuoteMailSuccess", FinishedQuote);
        }
        else return View();
    }
    

    and finally in the template (~/Views/QuoteMailer/QuoteMail.cshtml) you could use the model:

    @using AppName.Models
    @model QuoteModel
    
    Welcome to MvcMailer and enjoy your time!
    <br />
    <div class="mailer_entry">
        <div class="mailer_entry_box">
            <div class="mailer_entry_text">
                <h2>
                    INSERT_TITLE
                </h2>
                <p>
                    Hello @Model.FirstName
                </p>
                <p>
                    INSERT_CONTENT
                </p>
            </div>
        </div>
    </div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I don't know if this has been asked before, but what i'd like to
Don't know why this is happening, but after submitting a form via JS (using
Don't know why but I can't find a solution to this. I have 3
(Don't know if this is strictly on-topic, but I don't see any better Stack
Don't know if this has been asked before, so point me to another question
I don't know if this question is trivial or not. But after a couple
Don't know if this is the right place to ask this, but I will
Don't know if this is an eclipse specific problem but whenever I declare a
Don't know if this has been answered before. Have custom routes to users. If
Don't know if this is possible or not. But I'm trying to make it

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.