diff --git a/src/VS.Web.CG.Mvc/Templates/RazorPageGenerator/Bootstrap3/CreatePageModel.cshtml b/src/VS.Web.CG.Mvc/Templates/RazorPageGenerator/Bootstrap3/CreatePageModel.cshtml index 13282bcf8..6b0b980bf 100644 --- a/src/VS.Web.CG.Mvc/Templates/RazorPageGenerator/Bootstrap3/CreatePageModel.cshtml +++ b/src/VS.Web.CG.Mvc/Templates/RazorPageGenerator/Bootstrap3/CreatePageModel.cshtml @@ -6,6 +6,10 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; +@if (relatedProperties.Any()) +{ +using Microsoft.AspNetCore.Mvc.Filters; +} using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Mvc.Rendering; @{ @@ -40,12 +44,6 @@ namespace @Model.NamespaceName public IActionResult OnGet() { -@{ - foreach (var property in relatedProperties.Values) - { - @:ViewData["@(property.ForeignKeyPropertyNames[0])"] = new SelectList(_context.@property.EntitySetName, "@property.PrimaryKeyNames[0]", "@property.DisplayPropertyName"); - } -} return Page(); } @@ -64,5 +62,20 @@ namespace @Model.NamespaceName return RedirectToPage("./Index"); } +@if (relatedProperties.Any()) +{ + + public override Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next) + { +@{ + foreach (var property in relatedProperties.Values) + { + @:ViewData["@(property.ForeignKeyPropertyNames[0])"] = new SelectList(_context.@property.EntitySetName, "@property.PrimaryKeyNames[0]", "@property.DisplayPropertyName"); + } +} + + return base.OnPageHandlerExecutionAsync(context, next); + } +} } } \ No newline at end of file diff --git a/src/VS.Web.CG.Mvc/Templates/RazorPageGenerator/Bootstrap3/EditPageModel.cshtml b/src/VS.Web.CG.Mvc/Templates/RazorPageGenerator/Bootstrap3/EditPageModel.cshtml index ffb91f3c3..8b9e3fc00 100644 --- a/src/VS.Web.CG.Mvc/Templates/RazorPageGenerator/Bootstrap3/EditPageModel.cshtml +++ b/src/VS.Web.CG.Mvc/Templates/RazorPageGenerator/Bootstrap3/EditPageModel.cshtml @@ -6,6 +6,10 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; +@if (relatedProperties.Any()) +{ +using Microsoft.AspNetCore.Mvc.Filters; +} using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.EntityFrameworkCore; @@ -61,12 +65,7 @@ namespace @Model.NamespaceName { return NotFound(); } -@{ - foreach (var property in relatedProperties.Values) - { - @:ViewData["@(property.ForeignKeyPropertyNames[0])"] = new SelectList(_context.@property.EntitySetName, "@property.PrimaryKeyNames[0]", "@property.DisplayPropertyName"); - } -} + return Page(); } @@ -97,6 +96,21 @@ namespace @Model.NamespaceName return RedirectToPage("./Index"); } +@if (relatedProperties.Any()) +{ + + public override Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next) + { +@{ + foreach (var property in relatedProperties.Values) + { + @:ViewData["@(property.ForeignKeyPropertyNames[0])"] = new SelectList(_context.@property.EntitySetName, "@property.PrimaryKeyNames[0]", "@property.DisplayPropertyName"); + } +} + + return base.OnPageHandlerExecutionAsync(context, next); + } +} private bool @(Model.ModelTypeName)Exists(@primaryKeyShortTypeName id) { diff --git a/src/VS.Web.CG.Mvc/Templates/RazorPageGenerator/Bootstrap4/CreatePageModel.cshtml b/src/VS.Web.CG.Mvc/Templates/RazorPageGenerator/Bootstrap4/CreatePageModel.cshtml index 13282bcf8..6b0b980bf 100644 --- a/src/VS.Web.CG.Mvc/Templates/RazorPageGenerator/Bootstrap4/CreatePageModel.cshtml +++ b/src/VS.Web.CG.Mvc/Templates/RazorPageGenerator/Bootstrap4/CreatePageModel.cshtml @@ -6,6 +6,10 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; +@if (relatedProperties.Any()) +{ +using Microsoft.AspNetCore.Mvc.Filters; +} using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Mvc.Rendering; @{ @@ -40,12 +44,6 @@ namespace @Model.NamespaceName public IActionResult OnGet() { -@{ - foreach (var property in relatedProperties.Values) - { - @:ViewData["@(property.ForeignKeyPropertyNames[0])"] = new SelectList(_context.@property.EntitySetName, "@property.PrimaryKeyNames[0]", "@property.DisplayPropertyName"); - } -} return Page(); } @@ -64,5 +62,20 @@ namespace @Model.NamespaceName return RedirectToPage("./Index"); } +@if (relatedProperties.Any()) +{ + + public override Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next) + { +@{ + foreach (var property in relatedProperties.Values) + { + @:ViewData["@(property.ForeignKeyPropertyNames[0])"] = new SelectList(_context.@property.EntitySetName, "@property.PrimaryKeyNames[0]", "@property.DisplayPropertyName"); + } +} + + return base.OnPageHandlerExecutionAsync(context, next); + } +} } } \ No newline at end of file diff --git a/src/VS.Web.CG.Mvc/Templates/RazorPageGenerator/Bootstrap4/EditPageModel.cshtml b/src/VS.Web.CG.Mvc/Templates/RazorPageGenerator/Bootstrap4/EditPageModel.cshtml index ffb91f3c3..8b9e3fc00 100644 --- a/src/VS.Web.CG.Mvc/Templates/RazorPageGenerator/Bootstrap4/EditPageModel.cshtml +++ b/src/VS.Web.CG.Mvc/Templates/RazorPageGenerator/Bootstrap4/EditPageModel.cshtml @@ -6,6 +6,10 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; +@if (relatedProperties.Any()) +{ +using Microsoft.AspNetCore.Mvc.Filters; +} using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.EntityFrameworkCore; @@ -61,12 +65,7 @@ namespace @Model.NamespaceName { return NotFound(); } -@{ - foreach (var property in relatedProperties.Values) - { - @:ViewData["@(property.ForeignKeyPropertyNames[0])"] = new SelectList(_context.@property.EntitySetName, "@property.PrimaryKeyNames[0]", "@property.DisplayPropertyName"); - } -} + return Page(); } @@ -97,6 +96,21 @@ namespace @Model.NamespaceName return RedirectToPage("./Index"); } +@if (relatedProperties.Any()) +{ + + public override Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next) + { +@{ + foreach (var property in relatedProperties.Values) + { + @:ViewData["@(property.ForeignKeyPropertyNames[0])"] = new SelectList(_context.@property.EntitySetName, "@property.PrimaryKeyNames[0]", "@property.DisplayPropertyName"); + } +} + + return base.OnPageHandlerExecutionAsync(context, next); + } +} private bool @(Model.ModelTypeName)Exists(@primaryKeyShortTypeName id) { diff --git a/test/E2E_Test/Compiler/Resources/RazorPages/CarCreateCs.txt b/test/E2E_Test/Compiler/Resources/RazorPages/CarCreateCs.txt index 4c3607fdc..4c6d4e983 100644 --- a/test/E2E_Test/Compiler/Resources/RazorPages/CarCreateCs.txt +++ b/test/E2E_Test/Compiler/Resources/RazorPages/CarCreateCs.txt @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Mvc.Rendering; using Library1.Models; @@ -21,7 +22,6 @@ namespace TestProject public IActionResult OnGet() { - ViewData["ManufacturerID"] = new SelectList(_context.Set(), "ID", "ID"); return Page(); } @@ -40,5 +40,12 @@ namespace TestProject return RedirectToPage("./Index"); } + + public override Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next) + { + ViewData["ManufacturerID"] = new SelectList(_context.Set(), "ID", "ID"); + + return base.OnPageHandlerExecutionAsync(context, next); + } } } \ No newline at end of file diff --git a/test/E2E_Test/Compiler/Resources/RazorPages/CarCreateCsWithDAL.txt b/test/E2E_Test/Compiler/Resources/RazorPages/CarCreateCsWithDAL.txt index a0f6ecb7d..d7905a3b2 100644 --- a/test/E2E_Test/Compiler/Resources/RazorPages/CarCreateCsWithDAL.txt +++ b/test/E2E_Test/Compiler/Resources/RazorPages/CarCreateCsWithDAL.txt @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Mvc.Rendering; using DAL; @@ -21,7 +22,6 @@ namespace TestProject public IActionResult OnGet() { - ViewData["ManufacturerID"] = new SelectList(_context.Set(), "ID", "ID"); return Page(); } @@ -40,5 +40,12 @@ namespace TestProject return RedirectToPage("./Index"); } + + public override Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next) + { + ViewData["ManufacturerID"] = new SelectList(_context.Set(), "ID", "ID"); + + return base.OnPageHandlerExecutionAsync(context, next); + } } } \ No newline at end of file diff --git a/test/E2E_Test/Compiler/Resources/RazorPages/Crud/CreateCs.txt b/test/E2E_Test/Compiler/Resources/RazorPages/Crud/CreateCs.txt index 7be944b14..66f3a6312 100644 --- a/test/E2E_Test/Compiler/Resources/RazorPages/Crud/CreateCs.txt +++ b/test/E2E_Test/Compiler/Resources/RazorPages/Crud/CreateCs.txt @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Mvc.Rendering; using Library1.Models; @@ -21,7 +22,6 @@ namespace TestProject public IActionResult OnGet() { - ViewData["ManufacturerID"] = new SelectList(_context.Set(), "ID", "ID"); return Page(); } @@ -40,5 +40,12 @@ namespace TestProject return RedirectToPage("./Index"); } + + public override Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next) + { + ViewData["ManufacturerID"] = new SelectList(_context.Set(), "ID", "ID"); + + return base.OnPageHandlerExecutionAsync(context, next); + } } } \ No newline at end of file diff --git a/test/E2E_Test/Compiler/Resources/RazorPages/Crud/EditCs.txt b/test/E2E_Test/Compiler/Resources/RazorPages/Crud/EditCs.txt index c4a5a9503..6b630a9c6 100644 --- a/test/E2E_Test/Compiler/Resources/RazorPages/Crud/EditCs.txt +++ b/test/E2E_Test/Compiler/Resources/RazorPages/Crud/EditCs.txt @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.EntityFrameworkCore; @@ -37,7 +38,7 @@ namespace TestProject { return NotFound(); } - ViewData["ManufacturerID"] = new SelectList(_context.Set(), "ID", "ID"); + return Page(); } @@ -69,6 +70,13 @@ namespace TestProject return RedirectToPage("./Index"); } + public override Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next) + { + ViewData["ManufacturerID"] = new SelectList(_context.Set(), "ID", "ID"); + + return base.OnPageHandlerExecutionAsync(context, next); + } + private bool CarExists(string id) { return _context.Car.Any(e => e.ID == id);