0

I'm on "Microsoft.AspNet.Mvc": "6.0.0-rc1-final" and I don't see the configure method on AddMvc any longer and AddViewOptions.ViewEngine will throw

services.AddMvc().AddViewOptions(o =>
           {
               o.ViewEngines.Add(typeof(ICANRazorViewEngine));
               o.ViewEngines.Clear();
           });

gives me can't convert System.Type to IViewEngine?

What am i missing here?

Sen Gupta
  • 11
  • 1

1 Answers1

2

At the time of this writing (Mar-10-2016) the official ASP.NET Documentation to "Creating a Custom View Engine" (Page 299) was not available.

I was getting the same error using "Microsoft.AspNet.Mvc": "6.0.0-rc1-final", but because my intent was just include additional view locations, I fix it with:

public class CustomViewLocationExpander : IViewLocationExpander
{
    public void PopulateValues(ViewLocationExpanderContext context)
    {
    }

    public virtual IEnumerable<string> ExpandViewLocations(
        ViewLocationExpanderContext context,
        IEnumerable<string> viewLocations)
    {
        return viewLocations.Union(new string[] { "~/Views/{1}/PartialViews/{0}.cshtml" });
    }
}

and adding the code to Startup.cs

public void ConfigureServices(IServiceCollection services)
    {
        services
            .AddMvc()
            .AddRazorOptions(options =>
            {
                options.ViewLocationExpanders.Add(new CustomViewLocationExpander());
            })
            .AddViewLocalization(LanguageViewLocationExpanderFormat.SubFolder);
    }

I hope that could help you in some way.