我遇到了一个我什至无法合理化的最奇怪的问题。我有一个带有几个文本框的表单,其中一个是评论框:
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;
}
(不要问我为什么需要小评论和大评论,客户就是客户)
无论如何,我的问题是当我在评论框中输入评论时,我得到了这个回报:
但是,当我复制粘贴文本时,我得到了这个回报:
为什么会这样?