From 22cfd5def1868524b35fe58c0f637be1a150c737 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Melvyn=20La=C3=AFly?= Date: Tue, 16 Nov 2021 23:11:17 +0100 Subject: [PATCH 1/5] Update to .NET 6.0 and F# 6 --- .editorconfig | 21 ++++++++++++++++ Giraffe.Razor.sln | 25 ++++++++++--------- .../GiraffeRazorSample.fsproj | 6 ++--- samples/GiraffeRazorSample/Program.fs | 1 - src/Giraffe.Razor/Giraffe.Razor.fsproj | 7 +++--- src/Giraffe.Razor/HttpHandlers.fs | 3 +-- src/Giraffe.Razor/RazorEngine.fs | 3 +-- 7 files changed, 41 insertions(+), 25 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..0999d6e --- /dev/null +++ b/.editorconfig @@ -0,0 +1,21 @@ +############################### +# Core EditorConfig Options # +############################### +root = true +# All files +[*] +indent_style = space + +# XML project files +[*.{csproj,fsproj,vcxproj,vcxproj.filters,proj,projitems,shproj}] +indent_size = 2 + +# XML config files +[*.{props,targets,ruleset,config,nuspec,resx,vsixmanifest,vsct}] +indent_size = 2 + +# Code files +[*.{cs,csx,fs,fsx}] +indent_size = 4 +insert_final_newline = true +charset = utf-8 \ No newline at end of file diff --git a/Giraffe.Razor.sln b/Giraffe.Razor.sln index 077aa62..d4a62f4 100644 --- a/Giraffe.Razor.sln +++ b/Giraffe.Razor.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.26124.0 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31903.59 MinimumVisualStudioVersion = 15.0.26124.0 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{03CCBA43-B6F5-4FA7-8C18-432BB07225FC}" EndProject @@ -12,16 +12,17 @@ EndProject Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "GiraffeRazorSample", "samples\GiraffeRazorSample\GiraffeRazorSample.fsproj", "{14818084-9969-4F42-8A66-394FC6670B50}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "_root", "_root", "{73E09F74-F64D-4C42-92FC-19731C0C5553}" -ProjectSection(SolutionItems) = preProject - .gitignore = .gitignore - .gitattributes = .gitattributes - LICENSE = LICENSE - NuGet.config = NuGet.config - README.md = README.md - RELEASE_NOTES.md = RELEASE_NOTES.md - giraffe-64x64.png = giraffe-64x64.png - CODE_OF_CONDUCT.md = CODE_OF_CONDUCT.md -EndProjectSection + ProjectSection(SolutionItems) = preProject + .editorconfig = .editorconfig + .gitattributes = .gitattributes + .gitignore = .gitignore + CODE_OF_CONDUCT.md = CODE_OF_CONDUCT.md + giraffe-64x64.png = giraffe-64x64.png + LICENSE = LICENSE + NuGet.config = NuGet.config + README.md = README.md + RELEASE_NOTES.md = RELEASE_NOTES.md + EndProjectSection EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/samples/GiraffeRazorSample/GiraffeRazorSample.fsproj b/samples/GiraffeRazorSample/GiraffeRazorSample.fsproj index c56f144..e8af4e8 100644 --- a/samples/GiraffeRazorSample/GiraffeRazorSample.fsproj +++ b/samples/GiraffeRazorSample/GiraffeRazorSample.fsproj @@ -1,7 +1,7 @@ - + - net5.0 + net6.0 GiraffeRazorSample GiraffeRazorSample false @@ -13,8 +13,6 @@ - - diff --git a/samples/GiraffeRazorSample/Program.fs b/samples/GiraffeRazorSample/Program.fs index b866c00..83c7d5e 100644 --- a/samples/GiraffeRazorSample/Program.fs +++ b/samples/GiraffeRazorSample/Program.fs @@ -11,7 +11,6 @@ open Microsoft.AspNetCore.Http.Features open Microsoft.AspNetCore.Mvc.ModelBinding open Microsoft.Extensions.Logging open Microsoft.Extensions.DependencyInjection -open FSharp.Control.Tasks open Giraffe open Giraffe.Razor diff --git a/src/Giraffe.Razor/Giraffe.Razor.fsproj b/src/Giraffe.Razor/Giraffe.Razor.fsproj index 85ab485..243a3d9 100755 --- a/src/Giraffe.Razor/Giraffe.Razor.fsproj +++ b/src/Giraffe.Razor/Giraffe.Razor.fsproj @@ -11,7 +11,7 @@ $(NoWarn);NU5104 - net5.0 + net6.0 portable Library true @@ -45,9 +45,8 @@ - - - + + diff --git a/src/Giraffe.Razor/HttpHandlers.fs b/src/Giraffe.Razor/HttpHandlers.fs index cfca34a..9f811de 100644 --- a/src/Giraffe.Razor/HttpHandlers.fs +++ b/src/Giraffe.Razor/HttpHandlers.fs @@ -12,7 +12,6 @@ module HttpHandlers = open Microsoft.AspNetCore.Mvc.ViewFeatures open Microsoft.Extensions.DependencyInjection open Microsoft.AspNetCore.Antiforgery - open FSharp.Control.Tasks open Giraffe open RazorEngine @@ -55,4 +54,4 @@ module HttpHandlers = return! if isValid then next ctx else invalidTokenHandler (Some >> Task.FromResult) ctx - } \ No newline at end of file + } diff --git a/src/Giraffe.Razor/RazorEngine.fs b/src/Giraffe.Razor/RazorEngine.fs index 32cac04..1f203fe 100644 --- a/src/Giraffe.Razor/RazorEngine.fs +++ b/src/Giraffe.Razor/RazorEngine.fs @@ -13,7 +13,6 @@ module RazorEngine = open Microsoft.AspNetCore.Mvc.Rendering open Microsoft.AspNetCore.Mvc.ViewFeatures open Microsoft.AspNetCore.Routing - open FSharp.Control.Tasks let private extractRouteData (path : string) = // Normalize nulls @@ -80,4 +79,4 @@ module RazorEngine = do! view.RenderAsync(viewContext) tempDataDict.Save() return Ok (output.ToString()) - } \ No newline at end of file + } From 1f454e9391a1c56d90c5158d98297887dec2f807 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Melvyn=20La=C3=AFly?= Date: Tue, 16 Nov 2021 23:11:50 +0100 Subject: [PATCH 2/5] Extract the views to a C# project so we get full VS support in .cshtml files The models also had to move so they can be referenced both by the views and the web project. --- Giraffe.Razor.sln | 49 +++++++++++++++---- .../GiraffeRazorSample.fsproj | 13 ++--- samples/GiraffeRazorSample/Program.fs | 31 ++++-------- .../{WebRoot => wwwroot}/main.css | 0 samples/Models/Models.fs | 18 +++++++ samples/Models/Models.fsproj | 12 +++++ .../RazorClassLibrary.csproj | 28 +++++++++++ .../Views/CreatePerson.cshtml | 4 +- .../Views/FileUpload.cshtml | 0 .../Views/Hello.cshtml | 0 .../Views/Partial.cshtml | 0 .../Views/Person.cshtml | 2 +- .../Views/_Layout.cshtml | 0 .../Views/_ViewStart.cshtml | 0 14 files changed, 115 insertions(+), 42 deletions(-) rename samples/GiraffeRazorSample/{WebRoot => wwwroot}/main.css (100%) create mode 100644 samples/Models/Models.fs create mode 100644 samples/Models/Models.fsproj create mode 100644 samples/RazorClassLibrary/RazorClassLibrary.csproj rename samples/{GiraffeRazorSample => RazorClassLibrary}/Views/CreatePerson.cshtml (95%) rename samples/{GiraffeRazorSample => RazorClassLibrary}/Views/FileUpload.cshtml (100%) rename samples/{GiraffeRazorSample => RazorClassLibrary}/Views/Hello.cshtml (100%) rename samples/{GiraffeRazorSample => RazorClassLibrary}/Views/Partial.cshtml (100%) rename samples/{GiraffeRazorSample => RazorClassLibrary}/Views/Person.cshtml (81%) rename samples/{GiraffeRazorSample => RazorClassLibrary}/Views/_Layout.cshtml (100%) rename samples/{GiraffeRazorSample => RazorClassLibrary}/Views/_ViewStart.cshtml (100%) diff --git a/Giraffe.Razor.sln b/Giraffe.Razor.sln index d4a62f4..3f4aa1d 100644 --- a/Giraffe.Razor.sln +++ b/Giraffe.Razor.sln @@ -5,11 +5,11 @@ VisualStudioVersion = 17.0.31903.59 MinimumVisualStudioVersion = 15.0.26124.0 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{03CCBA43-B6F5-4FA7-8C18-432BB07225FC}" EndProject -Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Giraffe.Razor", "src\Giraffe.Razor\Giraffe.Razor.fsproj", "{9B52367B-CC80-452E-9062-7583995BFAC0}" +Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Giraffe.Razor", "src\Giraffe.Razor\Giraffe.Razor.fsproj", "{9B52367B-CC80-452E-9062-7583995BFAC0}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{E067A6B8-538E-4362-83C2-9ECBC486AC31}" EndProject -Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "GiraffeRazorSample", "samples\GiraffeRazorSample\GiraffeRazorSample.fsproj", "{14818084-9969-4F42-8A66-394FC6670B50}" +Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "GiraffeRazorSample", "samples\GiraffeRazorSample\GiraffeRazorSample.fsproj", "{14818084-9969-4F42-8A66-394FC6670B50}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "_root", "_root", "{73E09F74-F64D-4C42-92FC-19731C0C5553}" ProjectSection(SolutionItems) = preProject @@ -24,6 +24,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "_root", "_root", "{73E09F74 RELEASE_NOTES.md = RELEASE_NOTES.md EndProjectSection EndProject +Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Models", "samples\Models\Models.fsproj", "{7FF78E51-A357-4D4B-90FF-B03E148AE18C}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RazorClassLibrary", "samples\RazorClassLibrary\RazorClassLibrary.csproj", "{0A429935-F750-4334-98BE-9FC26764A174}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -33,13 +37,6 @@ Global Release|x64 = Release|x64 Release|x86 = Release|x86 EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(NestedProjects) = preSolution - {9B52367B-CC80-452E-9062-7583995BFAC0} = {03CCBA43-B6F5-4FA7-8C18-432BB07225FC} - {14818084-9969-4F42-8A66-394FC6670B50} = {E067A6B8-538E-4362-83C2-9ECBC486AC31} - EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {9B52367B-CC80-452E-9062-7583995BFAC0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {9B52367B-CC80-452E-9062-7583995BFAC0}.Debug|Any CPU.Build.0 = Debug|Any CPU @@ -65,5 +62,39 @@ Global {14818084-9969-4F42-8A66-394FC6670B50}.Release|x64.Build.0 = Release|Any CPU {14818084-9969-4F42-8A66-394FC6670B50}.Release|x86.ActiveCfg = Release|Any CPU {14818084-9969-4F42-8A66-394FC6670B50}.Release|x86.Build.0 = Release|Any CPU + {7FF78E51-A357-4D4B-90FF-B03E148AE18C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7FF78E51-A357-4D4B-90FF-B03E148AE18C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7FF78E51-A357-4D4B-90FF-B03E148AE18C}.Debug|x64.ActiveCfg = Debug|Any CPU + {7FF78E51-A357-4D4B-90FF-B03E148AE18C}.Debug|x64.Build.0 = Debug|Any CPU + {7FF78E51-A357-4D4B-90FF-B03E148AE18C}.Debug|x86.ActiveCfg = Debug|Any CPU + {7FF78E51-A357-4D4B-90FF-B03E148AE18C}.Debug|x86.Build.0 = Debug|Any CPU + {7FF78E51-A357-4D4B-90FF-B03E148AE18C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7FF78E51-A357-4D4B-90FF-B03E148AE18C}.Release|Any CPU.Build.0 = Release|Any CPU + {7FF78E51-A357-4D4B-90FF-B03E148AE18C}.Release|x64.ActiveCfg = Release|Any CPU + {7FF78E51-A357-4D4B-90FF-B03E148AE18C}.Release|x64.Build.0 = Release|Any CPU + {7FF78E51-A357-4D4B-90FF-B03E148AE18C}.Release|x86.ActiveCfg = Release|Any CPU + {7FF78E51-A357-4D4B-90FF-B03E148AE18C}.Release|x86.Build.0 = Release|Any CPU + {0A429935-F750-4334-98BE-9FC26764A174}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0A429935-F750-4334-98BE-9FC26764A174}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0A429935-F750-4334-98BE-9FC26764A174}.Debug|x64.ActiveCfg = Debug|Any CPU + {0A429935-F750-4334-98BE-9FC26764A174}.Debug|x64.Build.0 = Debug|Any CPU + {0A429935-F750-4334-98BE-9FC26764A174}.Debug|x86.ActiveCfg = Debug|Any CPU + {0A429935-F750-4334-98BE-9FC26764A174}.Debug|x86.Build.0 = Debug|Any CPU + {0A429935-F750-4334-98BE-9FC26764A174}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0A429935-F750-4334-98BE-9FC26764A174}.Release|Any CPU.Build.0 = Release|Any CPU + {0A429935-F750-4334-98BE-9FC26764A174}.Release|x64.ActiveCfg = Release|Any CPU + {0A429935-F750-4334-98BE-9FC26764A174}.Release|x64.Build.0 = Release|Any CPU + {0A429935-F750-4334-98BE-9FC26764A174}.Release|x86.ActiveCfg = Release|Any CPU + {0A429935-F750-4334-98BE-9FC26764A174}.Release|x86.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {9B52367B-CC80-452E-9062-7583995BFAC0} = {03CCBA43-B6F5-4FA7-8C18-432BB07225FC} + {14818084-9969-4F42-8A66-394FC6670B50} = {E067A6B8-538E-4362-83C2-9ECBC486AC31} + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {8D44B626-1BB8-4B87-8E9F-045072A0598C} EndGlobalSection EndGlobal diff --git a/samples/GiraffeRazorSample/GiraffeRazorSample.fsproj b/samples/GiraffeRazorSample/GiraffeRazorSample.fsproj index e8af4e8..ff1d0e6 100644 --- a/samples/GiraffeRazorSample/GiraffeRazorSample.fsproj +++ b/samples/GiraffeRazorSample/GiraffeRazorSample.fsproj @@ -10,22 +10,17 @@ + + - - - + + - - - Always - - - diff --git a/samples/GiraffeRazorSample/Program.fs b/samples/GiraffeRazorSample/Program.fs index 83c7d5e..b1be3e3 100644 --- a/samples/GiraffeRazorSample/Program.fs +++ b/samples/GiraffeRazorSample/Program.fs @@ -13,23 +13,7 @@ open Microsoft.Extensions.Logging open Microsoft.Extensions.DependencyInjection open Giraffe open Giraffe.Razor - -// --------------------------------- -// Models -// --------------------------------- - -[] -type Person = - { - Name : string - } - -[] -type CreatePerson = - { - Name : string - CheckMe : bool - } +open Models // --------------------------------- // Web app @@ -80,7 +64,7 @@ let renderPerson = let renderCreatePerson = let model = { Name = ""; CheckMe = true } - let viewData = dict [("Title", box "Create peson")] + let viewData = dict [("Title", box "Create person")] razorHtmlView "CreatePerson" (Some model) (Some viewData) None let createPerson = @@ -96,7 +80,7 @@ let createPerson = let url = sprintf "/person?name=%s" model.Name return! redirectTo false url next ctx else - let viewData = dict [("Title", box "Create peson")] + let viewData = dict [("Title", box "Create person")] return! razorHtmlView "CreatePerson" (Some model) (Some viewData) (Some modelState) next ctx } @@ -147,9 +131,14 @@ let configureServices (services : IServiceCollection) = let sp = services.BuildServiceProvider() let env = sp.GetService() services.AddGiraffe() |> ignore - Path.Combine(env.ContentRootPath, "Views") + services.AddMvc() |> ignore // Required for Razor views to work, regardless of runtime compilation or not. + // Only use Razor runtime compilation in DEBUG (For hot reload to work) + // The statically compiled views are used in Release mode. +#if DEBUG + Path.GetFullPath(Path.Combine(env.ContentRootPath, "..", "RazorClassLibrary")) |> services.AddRazorEngine |> ignore +#endif let configureLogging (loggerBuilder : ILoggingBuilder) = loggerBuilder.AddFilter(fun lvl -> lvl.Equals LogLevel.Error) @@ -167,4 +156,4 @@ let main _ = .ConfigureLogging(configureLogging) .Build() .Run() - 0 \ No newline at end of file + 0 diff --git a/samples/GiraffeRazorSample/WebRoot/main.css b/samples/GiraffeRazorSample/wwwroot/main.css similarity index 100% rename from samples/GiraffeRazorSample/WebRoot/main.css rename to samples/GiraffeRazorSample/wwwroot/main.css diff --git a/samples/Models/Models.fs b/samples/Models/Models.fs new file mode 100644 index 0000000..9dcabba --- /dev/null +++ b/samples/Models/Models.fs @@ -0,0 +1,18 @@ +namespace Models + +// --------------------------------- +// Models +// --------------------------------- + +[] +type Person = + { + Name : string + } + +[] +type CreatePerson = + { + Name : string + CheckMe : bool + } \ No newline at end of file diff --git a/samples/Models/Models.fsproj b/samples/Models/Models.fsproj new file mode 100644 index 0000000..847ab8e --- /dev/null +++ b/samples/Models/Models.fsproj @@ -0,0 +1,12 @@ + + + + net6.0 + true + + + + + + + diff --git a/samples/RazorClassLibrary/RazorClassLibrary.csproj b/samples/RazorClassLibrary/RazorClassLibrary.csproj new file mode 100644 index 0000000..68e99cb --- /dev/null +++ b/samples/RazorClassLibrary/RazorClassLibrary.csproj @@ -0,0 +1,28 @@ + + + + net6.0 + enable + enable + + + true + + + + + + + + + + + + + + + + + + + diff --git a/samples/GiraffeRazorSample/Views/CreatePerson.cshtml b/samples/RazorClassLibrary/Views/CreatePerson.cshtml similarity index 95% rename from samples/GiraffeRazorSample/Views/CreatePerson.cshtml rename to samples/RazorClassLibrary/Views/CreatePerson.cshtml index b8632e5..a556166 100644 --- a/samples/GiraffeRazorSample/Views/CreatePerson.cshtml +++ b/samples/RazorClassLibrary/Views/CreatePerson.cshtml @@ -1,11 +1,11 @@ -@model GiraffeRazorSample.CreatePerson +@model Models.CreatePerson @{ Layout = "_Layout"; } @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
-

Create Person

+

@ViewData["Title"]

diff --git a/samples/GiraffeRazorSample/Views/FileUpload.cshtml b/samples/RazorClassLibrary/Views/FileUpload.cshtml similarity index 100% rename from samples/GiraffeRazorSample/Views/FileUpload.cshtml rename to samples/RazorClassLibrary/Views/FileUpload.cshtml diff --git a/samples/GiraffeRazorSample/Views/Hello.cshtml b/samples/RazorClassLibrary/Views/Hello.cshtml similarity index 100% rename from samples/GiraffeRazorSample/Views/Hello.cshtml rename to samples/RazorClassLibrary/Views/Hello.cshtml diff --git a/samples/GiraffeRazorSample/Views/Partial.cshtml b/samples/RazorClassLibrary/Views/Partial.cshtml similarity index 100% rename from samples/GiraffeRazorSample/Views/Partial.cshtml rename to samples/RazorClassLibrary/Views/Partial.cshtml diff --git a/samples/GiraffeRazorSample/Views/Person.cshtml b/samples/RazorClassLibrary/Views/Person.cshtml similarity index 81% rename from samples/GiraffeRazorSample/Views/Person.cshtml rename to samples/RazorClassLibrary/Views/Person.cshtml index c466701..0faa853 100644 --- a/samples/GiraffeRazorSample/Views/Person.cshtml +++ b/samples/RazorClassLibrary/Views/Person.cshtml @@ -1,4 +1,4 @@ -@model GiraffeRazorSample.Person +@model Models.Person @{ Layout = "_Layout"; } diff --git a/samples/GiraffeRazorSample/Views/_Layout.cshtml b/samples/RazorClassLibrary/Views/_Layout.cshtml similarity index 100% rename from samples/GiraffeRazorSample/Views/_Layout.cshtml rename to samples/RazorClassLibrary/Views/_Layout.cshtml diff --git a/samples/GiraffeRazorSample/Views/_ViewStart.cshtml b/samples/RazorClassLibrary/Views/_ViewStart.cshtml similarity index 100% rename from samples/GiraffeRazorSample/Views/_ViewStart.cshtml rename to samples/RazorClassLibrary/Views/_ViewStart.cshtml From bcc7e7b0811919a0e12c40bb976418b09315082b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Melvyn=20La=C3=AFly?= Date: Tue, 16 Nov 2021 23:29:33 +0100 Subject: [PATCH 3/5] Fix error because text cannot be serialized --- samples/GiraffeRazorSample/Program.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/GiraffeRazorSample/Program.fs b/samples/GiraffeRazorSample/Program.fs index b1be3e3..7ca846c 100644 --- a/samples/GiraffeRazorSample/Program.fs +++ b/samples/GiraffeRazorSample/Program.fs @@ -115,7 +115,7 @@ let webApp = let errorHandler (ex : Exception) (logger : ILogger) = logger.LogError(EventId(), ex, "An unhandled exception has occurred while executing the request.") - clearResponse >=> ServerErrors.INTERNAL_ERROR (text ex.Message) + clearResponse >=> ServerErrors.INTERNAL_ERROR ex.Message // --------------------------------- // Main From d195fef82657927feb3bafc017b203c2812e7156 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Melvyn=20La=C3=AFly?= Date: Tue, 16 Nov 2021 23:29:49 +0100 Subject: [PATCH 4/5] Fix null IFormFeature --- samples/GiraffeRazorSample/Program.fs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/samples/GiraffeRazorSample/Program.fs b/samples/GiraffeRazorSample/Program.fs index 7ca846c..8a0ff12 100644 --- a/samples/GiraffeRazorSample/Program.fs +++ b/samples/GiraffeRazorSample/Program.fs @@ -45,6 +45,10 @@ let smallFileUploadHandler = let largeFileUploadHandler = fun (next : HttpFunc) (ctx : HttpContext) -> task { + // Simply accessing this property triggers something necessary + // for the IFormFeature instance to be injected (without this, it's null) + // see https://stackoverflow.com/questions/65967338/how-do-i-enable-iformfeature-in-asp-net-kestrel + let formContentType = ctx.Request.HasFormContentType let formFeature = ctx.Features.Get() let! form = formFeature.ReadFormAsync CancellationToken.None return! (form.Files |> displayFileInfos) next ctx From c885b9813c318c77f2228812a2e7bc9496e58660 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Melvyn=20La=C3=AFly?= Date: Tue, 16 Nov 2021 23:30:33 +0100 Subject: [PATCH 5/5] Add a more complete index and another navigation link in the partial view --- samples/GiraffeRazorSample/Program.fs | 14 +++++++++++++- samples/RazorClassLibrary/Views/Partial.cshtml | 3 ++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/samples/GiraffeRazorSample/Program.fs b/samples/GiraffeRazorSample/Program.fs index 8a0ff12..70792ce 100644 --- a/samples/GiraffeRazorSample/Program.fs +++ b/samples/GiraffeRazorSample/Program.fs @@ -95,11 +95,23 @@ let viewData = "Bar", true :> obj ] +let renderIndex = + """ +

non razor index

+ + """ + |> htmlString + let webApp = choose [ GET >=> choose [ - route "/" >=> text "index" + route "/" >=> renderIndex route "/razor" >=> razorView "text/html" "Hello" None (Some viewData) None route "/person/create" >=> renderCreatePerson route "/person" >=> renderPerson diff --git a/samples/RazorClassLibrary/Views/Partial.cshtml b/samples/RazorClassLibrary/Views/Partial.cshtml index 39e34f9..745cdd3 100644 --- a/samples/RazorClassLibrary/Views/Partial.cshtml +++ b/samples/RazorClassLibrary/Views/Partial.cshtml @@ -1,2 +1,3 @@

Greetings @ViewData["Title"]

-

Some partial text.

\ No newline at end of file +

Some partial text.

+Create a new person! \ No newline at end of file