0

我的网站上有反馈表,我需要在
我拥有的电子邮件中添加附件

  @Html.TextBoxFor(model => model.ProjectInformation, null, new { type = "file", @class = "input-file" })

=

<input type="file" id="ProjectInformation">

我在我的控制器中编写该代码

        //Attachment
        if (Model.ProjectInformation != null && !(String.IsNullOrEmpty(Model.ProjectInformation.FileName)))
        {
            HttpPostedFileBase hpf = this.Request.Files[Model.ProjectInformation.FileName];
            if (hpf.ContentLength > 0)
            {
                var attach = new Attachment(hpf.InputStream, Model.ProjectInformation.FileName);
                msg.Attachments.Add(attach);
            }
        }

但是我收到没有附件的电子邮件,当我签入调试器时,我看到了
Model.ProjectInformation = null

但我不明白为什么?

4

1 回答 1

1

Model.ProjectInformation已经HttpPostedFileBase是您认为的,您无需尝试从请求中获取文件。

[HttpPost]
public ActionResult Feedback(FeedbackForm Model)
{
    //Attachment
    if (Model.ProjectInformation != null && !(String.IsNullOrEmpty(Model.ProjectInformation.FileName)))
    {
        HttpPostedFileBase hpf = Model.ProjectInformation;
        if (hpf.ContentLength > 0)
        {
            var attach = new Attachment(hpf.InputStream, Model.ProjectInformation.FileName);
            msg.Attachments.Add(attach);
        }
    }
}
于 2013-05-23T14:20:28.497 回答