控制器中变量的串联 [英] concatenation of variables in a Controller
问题描述
我将以下代码从我的网站中的联系表单发送到我的电子邮件中。截至目前,它发送的只是评论。我需要在内容中连接model.Phone,model.email和model.Name中的值,以便我可以接收所有信息。
我有几行评论说应该有效,但不是。我必须去上班,明天我会恢复并回答任何问题,但我想在这里找ASP神,这可能会绰绰有余;)
谢谢费拉斯
I the following code that sends the information from a contact form in my website to my email. As of right now, all it sends is the comments. I need to concatenate the values inside model.Phone, model.email, and model.Name inside the content so that I can receive all information.
I have a few lines commented out that are supposed to work, but don''t. I have to get to work and I will resume and answer here tomorrow to any questions but I figure for the ASP Gods here, this is probably going to be more than enough ;)
Thanks fellas
[HttpPost]
public ActionResult Contact(ContactsModel model)
{
if (ModelState.IsValid)
{
InsertContact(model.Name, model.Phone, model.Email, model.Comments);
SmtpClient MySMTPClient;
MailMessage myEmail;
MySMTPClient = new SmtpClient("smtp.live.com", 25);
MySMTPClient.Credentials = new NetworkCredential("lotusms@outlook.com", "1qaz1qaz");
MySMTPClient.EnableSsl = true;
myEmail = new MailMessage(new MailAddress(model.Email), new MailAddress("lotusms@outlook.com"));
myEmail.Body = model.Comments;
myEmail.Subject = "Email from an Azure app!";
//string[] args = { "Name : ", model.Name, "\nPhone : ", model.Phone, "\nComments : ", model.Comments };
//string strBody = String.Concat(args);
MySMTPClient.Send(myEmail);
TempData["notice"] = "Someone will reply as soon as possible.";
return RedirectToAction("Index", "Home");
}
return View();
}
private void InsertContact(string Name, string Phone, string Email, string Comments)
{
}
推荐答案
为什么要连续?使用:
Why concat? Use this:
string strBody = String.Format("Name : {0}\nPhone : {1}\nComments : {2}", model.Name, model.Phone, model.Comments)
但是如果你想使用剃刀引擎本身来呈现一个更有趣的方法更复杂的邮件正文: http:// www .west-wind.com / weblog / posts / 2012 / May / 30 / Rendering-ASPNET-MVC-Views-to-String [ ^ ]。
这篇关于控制器中变量的串联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!