MVC 3 アプリケーションを開発しており、MvcMailer を使用して電子メールを送信しています。基本的な電子メールは送信できますが、フォームの内容を電子メールで送信しようとしてもうまくいきません。
私のモデルのコードは次のとおりです。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
namespace DFPProductions_Default.Models
{
public class Application
{
[Required]
[Display(Name = "First Name")]
public string ApplicantFirstName { get; set; }
[Required]
[Display(Name = "Last Name")]
public string ApplicantLastName { get; set; }
[Display(Name = "Birth Date")]
public DateTime ApplicantBirthDate { get; set; }
[Required]
[Display(Name = "Cellphone Number")]
public string ApplicantCellphoneNumber { get; set; }
[Display(Name = "Postal Address")]
public string PostalNumber { get; set; }
[Display(Name = "Suburb")]
public string ApplicantSuburb { get; set; }
[Display(Name = "City")]
public string ApplicantCity { get; set; }
[Display(Name = "Post Code")]
public string ApplicationPostalCode { get; set; }
[Required]
[Display(Name = "Email Address")]
public string ApplicantEmailAddress { get; set; }
[Display(Name = "First Name")]
public string ParentFirstName { get; set; }
[Display(Name = "Last Name")]
public string ParentLastName { get; set; }
[Display(Name = "Email Address")]
public string ParentEmailAddress { get; set; }
[Display(Name = "Postal Address")]
public string ParentPostalNumber { get; set; }
[Display(Name = "Suburb")]
public string ParentSuburb { get; set; }
[Display(Name = "City")]
public string ParentCity {get; set;}
[Display(Name = "Post Code")]
public string ParentPostalCode {get; set;}
}
}
私の見解では、エディター フィールドがあります。ここにいくつかを示します。
<div class="editor-label">
@Html.LabelFor(model => model.ApplicantFirstName)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.ApplicantFirstName)
@Html.ValidationMessageFor(model => model.ApplicantFirstName)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.ApplicantLastName)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.ApplicantLastName)
@Html.ValidationMessageFor(model => model.ApplicantLastName)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.ApplicantBirthDate)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.ApplicantBirthDate)
@Html.ValidationMessageFor(model => model.ApplicantBirthDate)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.ApplicantCellphoneNumber)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.ApplicantCellphoneNumber)
@Html.ValidationMessageFor(model => model.ApplicantCellphoneNumber)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.ApplicantEmailAddress)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.ApplicantEmailAddress)
@Html.ValidationMessageFor(model => model.ApplicantEmailAddress)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.PostalNumber)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.PostalNumber)
@Html.ValidationMessageFor(model => model.ApplicantEmailAddress)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.ApplicantSuburb)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.ApplicantSuburb)
@Html.ValidationMessageFor(model => model.ApplicantSuburb)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.ApplicantCity)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.ApplicantCity)
@Html.ValidationMessageFor(model => model.ApplicantCity)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.ApplicationPostalCode)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.ApplicationPostalCode)
@Html.ValidationMessageFor(model => model.ApplicationPostalCode)
</div>
</div>
私は電子メールアプリケーションを呼び出しました。ApplicationMailer のコードは次のとおりです。
public virtual MailMessage Application()
{
var mailMessage = new MailMessage{Subject = "Application"};
mailMessage.To.Add("debbie@gmail.com");
ViewBag.Data = "Debbie";
PopulateBody(mailMessage, viewName: "Application");
return mailMessage;
}
コントローラーにこれがあります:
private IApplicationMailer _applicationMailer = new ApplicationMailer();
public IApplicationMailer ApplicationMailer
{
get { return _applicationMailer; }
set { _applicationMailer = value; }
}
public ActionResult SendApplication()
{
ApplicationMailer.Application().Send();
//Send() extension method: using Mvc.Mailer
return RedirectToAction("Index");
}
メールのビューに追加したのは
@model DFPProductions_Default.Models.Application
電子メールが送信されるので、正しく構成されていますが、電子メール ビューのフォームに挿入された値を取得する方法がよくわかりません。
ありがとう、エイミー