I am trying to use the NancyFX inline view function, but could not do it. I used this example . But still, it seems that Nancy is not using ResourceViewLocationProviderto search for my submission.
My bootstrapp configuration,
protected override void ConfigureApplicationContainer(IKernel existingContainer)
{
base.ConfigureApplicationContainer(existingContainer);
var currentAssembly = GetType().Assembly;
ResourceViewLocationProvider.RootNamespaces.Add(currentAssembly, "Candidate.Nancy.SelfHosted.Views");
}
protected override NancyInternalConfiguration InternalConfiguration
{
get { return NancyInternalConfiguration.WithOverrides(x => x.ViewLocationProvider = typeof(ResourceViewLocationProvider)); }
}
My module
public class AccountModule : NancyModule
{
private readonly IUserManagement _userManagement;
public AccountModule(IUserManagement userManagement) : base("/account")
{
_userManagement = userManagement;
Get["/login"] = p => View["Login.cshtml"];
}
}
Login.cshtml is placed in /Views/Account/Login.cshtml and is marked as an embedded resource.
If I run the application, I received HTTP 500. It seems he is trying to find it on the file system instead of build resources.
Nancy.RequestExecutionException: Oh noes! --- > Nancy.ViewEngines.ViewNotFoundException: 'Login.cshtml' : sshtml, html, htm, cshtml, vbhtml : Login.cshtml, /Login.cshtml, //Login.cshtml, /Login.cshtml, //Login.cshtml, /Login.cshtml : D:\Development\\candidate.net\SRC\Candidate.Nancy.Selfhosted\Bin\Debug Nancy.ViewEngines.DefaultViewFactory.GetRenderedView( viewName, Object model, ViewLocationContext viewLocationContext) at System.Dynamic.UpdateDelegates.UpdateAndExecute4 [0, 1, 2, 3, Tret] (CallSite , T0 arg0, T1 arg1, T2 arg2, T3 arg3) Nancy.ViewEngines.DefaultViewFactory.RenderView(String viewName, , ViewLocationContext viewLocationContext) Nancy.NancyModule.ViewRenderer.get_Item (String viewName) Candidate.Nancy.Selfhosted.Modules.AccountModule. <.ctor > b__0 (Object p) D:\Development\\candidate.net\SRC\Candidate.Nancy.Selfhosted\Modules\AccountModule.cs: 17 Nancy.Routing.Route.Invoke( DynamicDictionary)
Nancy.NancyEngine.ResolveAndInvokeRoute( NancyContext) Nancy.NancyEngine.InvokeRequestLifeCycle( NancyContext, IPipelines) --- ---
Nancy.NancyEngine.InvokeOnErrorHook( NancyContext, ErrorPipeline, Exception ex)
: Nancy 0.12.1.0.