I am messing about trying to implement my own basic view engine in F# at the moment. Essentially I am inheriting from the VirtualPathProviderViewEngine.
To do this I need to set two view locations so the engine knows where to look for the views. In my F# type I inherit from the above and try to set the two view locations as below…
type FSharpViewEngine() =
inherit VirtualPathProviderViewEngine()
let viewLocations = [| "~/Views/{1}/{0}.fshtml"; "~/Views/Shared/{0}.fshtml" |]
member this.ViewLocationFormats = viewLocations
member this.PartialViewLocationFormats = viewLocations
The code above omits the overrides that are needed for the VirtualPathProviderViewEngine.
I run the project and I get an error message to say
The property ‘ViewLocationFormats’ cannot be null or empty.
Which I am assuming means that I am not setting the two base members correctly above. Am I just assigning the above incorrectly or do you suspect I am doing something else wrong?
As extra info, I have added the ViewEngine at start up time in the Global.fs (global.asax) like so…
ViewEngines.Engines.Add(new FSharpViewEngine())
If you just want to set properties of a base class, then you do not need
memberoroverride, but instead you need to use the assignment operator<-in the constructor. To implement the engine, you’ll need to override two abstract methods that it defines, so you’ll need something like this: