のdbconfigに基づいてレイアウトが設定されているサイトがあります
~/Views/_ViewStart.cshtml like so
@{
Layout = ViewContext.ViewBag.MyConfig.ThemeName;
}
そして、独自の ViewStart を使用して Emails フォルダーをビューに追加した場合 ( Postal Nuget Package の場合)を除いて、すべて正常に機能しています
~/Views/Emails/_ViewStart.cshtml
を含む
@{ Layout = null; /* Overrides the Layout set for regular page views. */ }
HTML形式のメールをコードで送信するために使用されます
dynamic email = new Email("<nameofView>"); // this is in folder ~/Views/Emails/
email.To = to;
.... other fields....
email.Send();
ただし、この行で例外が発生します
Layout = ViewContext.ViewBag.MyConfig.ThemeName;
Cannot perform runtime binding on a null reference
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: Cannot perform runtime binding on a null reference
Source Error:
Line 1: @{
Line 2: Layout = ViewContext.ViewBag.MyConfig.ThemeName;
Line 3: }
~/Views/Emails からではなく ~/Views から ViewStart を取得する理由についての指針はありますか?