我試圖呈現一個視圖作爲字符串被用作電子郵件模板。我目前正在努力實現這個例子: https://weblog.west-wind.com/posts/2012/May/30/Rendering-ASPNET-MVC-Views-to-String渲染視圖作爲字符串
與這部分代碼但是我有困難:
public ViewRenderer(ControllerContext controllerContext = null)
{
// Create a known controller from HttpContext if no context is passed
if (controllerContext == null)
{
if (HttpContext.Current != null)
controllerContext = CreateController<ErrorController>().ControllerContext;
else
throw new InvalidOperationException(
"ViewRenderer must run in the context of an ASP.NET " +
"Application and requires HttpContext.Current to be present.");
}
Context = controllerContext;
}
Visual Studio是給我下面的錯誤:
"The type or namespace name 'ErrorController' could not be found (are you missing a using directive or an assembly reference?)"
我大概失蹤明顯的東西,但看不到它是什麼。有任何想法嗎?
你在你的項目中有一個'ErrorController'? – NightOwl888
不,我不知道這是否是可以添加一個標準化的控制器,或者如果它是我必須去創造。 – HuwD