0

我遇到了一个我什至无法合理化的最奇怪的问题。我有一个带有几个文本框的表单,其中一个是评论框:

MVC:

<div class="contactUsTextArea">
    Comments or Questions:<br />
    @Html.TextAreaFor(x => x.Comments, new { maxlength = 990 } )
</div>

呈现的 HTML:

<div class="contactUsTextArea">
    Comments or Questions:
    <br>
    <textarea id="Comments" rows="2" name="Comments" maxlength="990" cols="20"></textarea>
</div>

提交表单后,此代码运行:

public bool SendEmail(ContactUsModel formSubmission) {
    MailMessage email = new MailMessage();
    SmtpClient smtp = new SmtpClient();
    string upc = formSubmission.ProductUpcCode;
    string comments = formSubmission.Comments;
    string comments_small = formSubmission.Comments;

    if (!string.IsNullOrEmpty(formSubmission.ProductUpcCode) && upc.Length > 14 )
        upc = upc.Substring(0, 13);

    if (!string.IsNullOrEmpty(comments) && comments.Length > 990)
        comments = comments.Substring(0, 989);

    if (!string.IsNullOrEmpty(comments_small) && comments_small.Length > 255)
        comments_small = comments_small.Substring(0, 254);

    string bodyText = "FIRST_NAME:" + formSubmission.FirstName + "\n" +
                        "LAST_NAME:" + formSubmission.LastName + "\n" +
                        "COMPANY:" + formSubmission.CompanyName + "\n" +
                        "ADDRESS:" + formSubmission.StreetAddress + "\n" +
                        "CITY_TOWN:" + formSubmission.City + "\n" +
                        "STATE_PROVINCE:" + formSubmission.Province + "\n" +
                        "ZIP_POSTAL:" + formSubmission.PostalCode + "\n" +
                        "COUNTRY:CAN\n" +
                        "EMAIL:" + formSubmission.Email + "\n" +
                        "PHONE:" + formSubmission.PhoneNumber + "\n" +
                        "UPC:" + upc + "\n" +
                        "DATE_CODE:\n" +
                        "BRAND_PRODUCT:" + formSubmission.ProductName + "\n" +
                        "COMMENTS:" + comments_small + "\n" +
                        "FULL_COMMENTS:" + comments + "\n" +
                        "LANGUAGE:English" + "\n" +
                        "OPTIN:N";
    email.From = new MailAddress(ConfigurationManager.AppSettings["emailSubmission_FROM"]);
    email.To.Add(new MailAddress(ConfigurationManager.AppSettings["emailSubmission_TO"]));
    email.Subject = ConfigurationManager.AppSettings["emailSubmission_SUBJECT"];
    email.IsBodyHtml = false;
    email.Body = bodyText;
    email.BodyEncoding = System.Text.Encoding.UTF8;

    smtp.Send(email);            
    return true;
}

(不要问我为什么需要小评论和大评论,客户就是客户)

无论如何,我的问题是当我在评论框中输入评论时,我得到了这个回报:

http://i.imgur.com/zraNy.png

但是,当我复制粘贴文本时,我得到了这个回报:

http://i.imgur.com/doWrw.png

为什么会这样?

4

2 回答 2

1

这可能是(我能想到的)只有几件事——两者都与客户有关。

  • 与电子邮件客户端有关的东西,它没有呈现\n它应该呈现的样子。尽管对于 Windows,\r\n这是标准,但许多应用程序都不能正确地尊重 ' \n'。我会尝试将其用于换行符,而不仅仅是\n.
  • 还有一些与客户端有关的东西,与编码有关(但我对此表示怀疑)
于 2012-11-15T17:24:22.867 回答
1

好吧...所以我将发布我的问题的图片...然后我将永远躲在山洞里。

http://i.imgur.com/tEiKj.png

感谢大家的帮助。

于 2012-11-15T19:32:42.793 回答