Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 表单中的数据未通过电子邮件发送-MvcMailer_C#_Asp.net Mvc 3_Email_Mvcmailer - Fatal编程技术网

C# 表单中的数据未通过电子邮件发送-MvcMailer

C# 表单中的数据未通过电子邮件发送-MvcMailer,c#,asp.net-mvc-3,email,mvcmailer,C#,Asp.net Mvc 3,Email,Mvcmailer,我试图在我的MVC3Web应用程序中使用MvcMailer发送表单内容。电子邮件会发送,但不会填充表单中的数据 以下是我的表单视图: @using (Html.BeginForm()) { @Html.ValidationSummary(true) <div id="section_1" class="section"> <p style="color:#e93738;display:none"></p> <img src="/Content/

我试图在我的MVC3Web应用程序中使用MvcMailer发送表单内容。电子邮件会发送,但不会填充表单中的数据

以下是我的表单视图:

@using (Html.BeginForm())
{ 
@Html.ValidationSummary(true)

<div id="section_1" class="section"> 
<p style="color:#e93738;display:none"></p> 

<img src="/Content/1.png" id="one" class="step" alt="Step 1"/>  
<h3>Personal Details of Student</h3> 
<p> 
<em>Please enter your personal details.</em><br /> 

</p> 
<br />

    <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> 

<div id="section_2" class="section"> 
<img src="/Content/2.png" id="two" class="step" alt="Step 2"/>  
<h3>Parent Details</h3> 
<p> 
<em>Please enter your parent or guardian's details.</em><br /> 

</p> 

    <div class="editor-label">
        @Html.LabelFor(model => model.ParentFirstName)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.ParentFirstName)
        @Html.ValidationMessageFor(model => model.ParentFirstName)
    </div>

    <div class="editor-label">
        @Html.LabelFor(model => model.ParentLastName)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.ParentLastName)
        @Html.ValidationMessageFor(model => model.ParentLastName)
    </div>

    <div class="editor-label">
        @Html.LabelFor(model => model.ParentEmailAddress)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.ParentEmailAddress)
        @Html.ValidationMessageFor(model => model.ParentEmailAddress)
    </div>

    <div class="editor-label">
        @Html.LabelFor(model => model.ParentPostalNumber)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.ParentPostalNumber)
        @Html.ValidationMessageFor(model => model.ParentPostalNumber)
    </div>

   <div class="editor-label">
        @Html.LabelFor(model => model.ParentSuburb)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.ParentSuburb)
        @Html.ValidationMessageFor(model => model.ParentSuburb)
    </div>

     <div class="editor-label">
        @Html.LabelFor(model => model.ParentCity)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.ParentCity)
        @Html.ValidationMessageFor(model => model.ParentCity)
    </div>

     <div class="editor-label">
        @Html.LabelFor(model => model.ParentPostalCode)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.ParentPostalCode)
        @Html.ValidationMessageFor(model => model.ParentPostalCode)
    </div>

 </div> 
<a href='@Url.Action("SendApplication", "Home")'><input type="submit" value="Submit" /></a>
这是我的ApplicationMailer.cs:

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

        mailMessage.To.Add("amecily@gmail.com");
        ViewBag.Data = "Debbie";
        ViewBag.FirstName = application.ApplicantFirstName;
        ViewBag.LastName = application.ApplicantLastName;
        PopulateBody(mailMessage, viewName: "Application");

        return mailMessage;
    }
public interface IApplicationMailer
{

    MailMessage Application(Application application);

}
My IApplicationMailer.cs:

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

        mailMessage.To.Add("amecily@gmail.com");
        ViewBag.Data = "Debbie";
        ViewBag.FirstName = application.ApplicantFirstName;
        ViewBag.LastName = application.ApplicantLastName;
        PopulateBody(mailMessage, viewName: "Application");

        return mailMessage;
    }
public interface IApplicationMailer
{

    MailMessage Application(Application application);

}
和my Application.cshtml:

@model DFPProductions_Default.Models.Application

Hi @ViewBag.Data

A new application has been received:

@ViewBag.FirstName
@ViewBag.LastName
编辑:

在包含表单的视图顶部,我有:

@model DFPProductions_Default.Models.Application
而Application.cs是:

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;}


   }
}

我认为问题在于:

<a href='@Url.Action("SendApplication", "Home")'><input type="submit" value="Submit" /></a>

当您将断点放入应用程序邮件程序时,应用程序中是否填充了正确的数据?是否可以添加模型对象应用程序类的源?显然,模型绑定不起作用。您是否在视图中声明了模型?类似:@model应用程序