從我發現的文章略微修改,這似乎是正確的方式滾動。至少這是一個開始。
public interface IViewMailer string RenderPartialViewToString(string viewName,object model,ControllerContext controllerContext); }
public class ViewMailer : IViewMailer
{
#region IViewMailer Members
public string RenderPartialViewToString(string viewName, object model, ControllerContext controllerContext)
{
if (string.IsNullOrEmpty(viewName))
viewName = controllerContext.RouteData.GetRequiredString("action");
controllerContext.Controller.ViewData.Model = model;
using (var stringWriter = new StringWriter())
{
ViewEngineResult viewEngineResult = ViewEngines.Engines.FindPartialView(controllerContext, viewName);
var viewContext = new ViewContext(controllerContext, viewEngineResult.View,
controllerContext.Controller.ViewData,
controllerContext.Controller.TempData, stringWriter);
viewEngineResult.View.Render(viewContext, stringWriter);
return stringWriter.GetStringBuilder().ToString();
}
}
#endregion
}
讓我澄清一下,我十分精通於該System.Net.Mail命名空間。我的問題更多的是我認爲的建築問題。發送電子郵件很簡單;) – CrazyCoderz