diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Infrastructure/Conventions/BindJourneyInstancePropertiesConvention.cs b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Infrastructure/Conventions/BindJourneyInstancePropertiesConvention.cs new file mode 100644 index 0000000000..5addae2139 --- /dev/null +++ b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Infrastructure/Conventions/BindJourneyInstancePropertiesConvention.cs @@ -0,0 +1,19 @@ +using Microsoft.AspNetCore.Mvc.ApplicationModels; +using Microsoft.AspNetCore.Mvc.ModelBinding; + +namespace TeachingRecordSystem.SupportUi.Infrastructure.Conventions; + +public class BindJourneyInstancePropertiesConvention : IPageApplicationModelConvention +{ + public void Apply(PageApplicationModel model) + { + var journeyInstanceProperties = model.HandlerProperties.Where(p => + p.ParameterType == typeof(JourneyInstance) || + (p.ParameterType.IsGenericType && p.ParameterType.GetGenericTypeDefinition() == typeof(JourneyInstance<>))); + + foreach (var journeyInstanceProperty in journeyInstanceProperties) + { + journeyInstanceProperty.BindingInfo ??= new BindingInfo(); + } + } +} diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Program.cs b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Program.cs index 52de1fe24d..0d623b290e 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Program.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Program.cs @@ -17,6 +17,7 @@ using TeachingRecordSystem.Core.Infrastructure.Configuration; using TeachingRecordSystem.SupportUi; using TeachingRecordSystem.SupportUi.Infrastructure; +using TeachingRecordSystem.SupportUi.Infrastructure.Conventions; using TeachingRecordSystem.SupportUi.Infrastructure.Filters; using TeachingRecordSystem.SupportUi.Infrastructure.FormFlow; using TeachingRecordSystem.SupportUi.Infrastructure.ModelBinding; @@ -103,6 +104,8 @@ builder.Services .AddRazorPages(options => { + options.Conventions.Add(new BindJourneyInstancePropertiesConvention()); + options.Conventions.AddFolderApplicationModelConvention( "/Persons/PersonDetail", model =>