Setting base element values ​​in F #

I got confused in trying to implement my own basic viewing mechanism in F # at the moment. Essentially, I inherit from VirtualPathProviderViewEngine.

To do this, I need to set two views so that the engine knows where to look for submissions. In my F # class, I inherit the above and try to set two view layouts as shown 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 required for VirtualPathProviderViewEngine. I run a project and I get an error message to say

The "ViewLocationFormats" property cannot be empty or empty.

I assume that I am incorrectly setting the two basic elements above. Am I simply assigning the above incorrectly or do you suspect that I am doing something else wrong?

As additional information, I added ViewEngine during startup in Global.fs (global.asax), for example ...

 ViewEngines.Engines.Add(new FSharpViewEngine()) 
+4
source share
1 answer

If you just want to set the properties of the base class, you don't need member or override , but instead you need to use the <- assignment operator in the constructor. To implement the engine, you need to redefine two abstract methods that it defines, so you need something like this:

 type FSharpViewEngine() = inherit VirtualPathProviderViewEngine() let viewLocations = [| "~/Views/{1}/{0}.fshtml"; "~/Views/Shared/{0}.fshtml" |] do base.ViewLocationFormats <- viewLocations base.PartialViewLocationFormats <- viewLocations override x.CreatePartialView(ctx, path) = failwith "TODO!" override x.CreateView(ctx, viewPath, masterPath) = failwith "TODO!" 
+7
source

Source: https://habr.com/ru/post/1444340/


All Articles