MVC4:另存为HTML和电子邮件发送 [英] MVC4 : Save as html and email it
问题描述
我知道我问的信息在这里,但似乎是一个相关的问题,我没有得到任何想法如何做到这一点。请大家帮忙
问题:我们必须要求发送一封电子邮件,一个HTML附件。
发送电子邮件一部分是照顾作为我们的APT的一部分,但问题是用HTML附件。
要求:我们要发送的显示在用户界面为HTML文件的当前看法。
我怎样才能从视图控制器的完整HTML?
附件=新AttachmentContract
{
路径= AppSettings.NoticeAttachmentFilePath,
的FileName =filenamehtml,
含量=<<在这里,我们要设置HTML> >
}
找到了解决办法家伙带这里的一些其他问题的帮助是我在做什么。
附件=新AttachmentContract
{
路径= AppSettings.NoticeAttachmentFilePath,
的FileName =filenamehtml,
含量= TestMethod的()
}
私人字符串TestMethod的(ModelData modelData)
{
ViewData.Model = modelData;
StringWriter的输出;
使用(输出=新的StringWriter())
{
VAR的结果= ViewEngines.Engines.FindView(this.ControllerContext,EmailAttachment,NULL);
变种viewContext =新ViewContext(this.ControllerContext,result.View,this.ViewData,this.ControllerContext.Controller.TempData,输出);
result.View.Render(viewContext,输出);
result.ViewEngine.ReleaseView(this.ControllerContext,result.View);
}
返回output.ToString();
}
其中EmailAttachment一种观点我要去使用相同型号的
在我的逻辑来填补
I know i am asking for information here but seems like a relevant question and i am getting no ideas how to do it . please help.
Problem: We have requirements to send an email with a html attachment.
Sending E-mail part is taken care of as a part of our APT but the problem is with the html attachment.
Requirement: we have to send the current view which is displayed on the UI as a html file.
How can i get the full html in the controller from the view?
Attachment = new AttachmentContract
{
Path = AppSettings.NoticeAttachmentFilePath,
FileName = "filenamehtml",
Content = <<here we want to set that html>>
}
Found out the solution guys with the help of some other question here's what i am doing
Attachment = new AttachmentContract
{
Path = AppSettings.NoticeAttachmentFilePath,
FileName = "filenamehtml",
Content = testmethod()
}
private string TestMethod(ModelData modelData)
{
ViewData.Model = modelData;
StringWriter output;
using (output = new StringWriter())
{
var result = ViewEngines.Engines.FindView(this.ControllerContext, "EmailAttachment", null);
var viewContext = new ViewContext(this.ControllerContext, result.View, this.ViewData, this.ControllerContext.Controller.TempData, output);
result.View.Render(viewContext, output);
result.ViewEngine.ReleaseView(this.ControllerContext, result.View);
}
return output.ToString();
}
Where EmailAttachment is a view i am going to fill in my logic using the same model
这篇关于MVC4:另存为HTML和电子邮件发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!