に挿入:MvcMailer:モデルを通じてビューでユーザーの入力を取った後、私はこれを正しく説明していた場合、私は知らない、または溶液はかなり単純ですので、ここになった場合、メール
私はMvcMailerを使用していますしかしその前に、私はQuote.cshtmlと呼ばれるウィザード入力フォームを設定しました。 Quote.cshtmlの後ろに、QuoteModel.csというモデルを設定しました。
その最も基本的でQuote.cshtml(私は、ウィザード・ロジックのすべてを残し、唯一の入力を示しています):
<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(一つだけの入力を示す;注意:使用してDataAnnotationExtensions)
public class QuoteModel
{
[Required(ErrorMessage = "First Name required.")]
[Display(Name = "First Name:")]
public string FirstName { get; set; }
}
今私はIQuoteMailer.csを設定MvcMailer、QuoteMailer.cs、_Layout.cshtml、およびQuoteMail.cshtmlを統合しようとしています。 QuoteMail.cshtmlは、メールの受信者が最終的に見るものです。また、私はMvcMailerに必要な適切なコードを配置したQuoteController.csをセットアップしました。 QuoteMailer.csとQuoteController.csにあり、Quote.cshtml(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("[email protected]");
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はので、ここで表示されない、かなり標準です):
@*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>
最後に、QuoteController.csの関連部分(私はウィザードを使用しているので、問題の一部です)MvcMailerコードをどこに置くかを考え出すが、私は右のそれを持っているかもしれないと思うされています
パブリッククラスQuoteControllerを:コントローラ {
/// <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);
}
}
だから、私の混乱がどのようにあります私が作成したQuoteModelを渡すため、最終的にユーザーが入力したデータを受け取り、MvcMailerビューを生成することができます。
地域社会の協力をいただきありがとうございます。
アウトと約。回答ありがとうございます。後で確認し、進捗状況を報告します。 – REMESQ
これは素晴らしいことでした。ありがとう!適切にマーキングする。 – REMESQ
これはうまくいきましたが、PopulateBody関数がModelパラメータを持つと本当に期待していました。私は簡単に拡張メソッドを追加することができますね。 –