1 @inherits Microsoft.VisualStudio.Web.CodeGeneration.Templating.RazorTemplateBase
2 @using System.Collections.Generic
5 using System.Collections.Generic;
7 using System.Threading.Tasks;
8 using Microsoft.AspNetCore.Mvc;
9 using Microsoft.AspNetCore.Mvc.RazorPages;
10 using Microsoft.AspNetCore.Mvc.Rendering;
12 var entitySetName = Model.ModelMetadata.EntitySetName;
13 var entitySetVar = Model.EntitySetVariable ??
14 (String.IsNullOrEmpty(entitySetName)
16 : (entitySetName.Substring(0, length: 1).ToLowerInvariant() + entitySetName.Substring(1)));
18 var relatedProperties = new Dictionary<string, dynamic>();
19 foreach (var nav in Model.ModelMetadata.Navigations)
21 relatedProperties.Add(nav.AssociationPropertyName, nav);
24 foreach (var namespaceName in Model.RequiredNamespaces)
26 @:using @namespaceName;
30 namespace @Model.NamespaceName
32 public class @Model.PageModelClassName : PageModel
34 private readonly @Model.ContextTypeName _context;
36 public @(Model.PageModelClassName)(@Model.ContextTypeName context)
41 public IActionResult OnGet()
44 foreach (var property in relatedProperties.Values)
46 @:ViewData["@(property.ForeignKeyPropertyNames[0])"] = new SelectList(_context.@property.EntitySetName, "@property.PrimaryKeyNames[0]", "@property.DisplayPropertyName");
53 public @Model.ViewDataTypeShortName @Model.ViewDataTypeShortName { get; set; }
55 public async Task<IActionResult> OnPostAsync()
57 if (!ModelState.IsValid)
62 _context.@(Model.ModelTypeName).Add(@Model.ViewDataTypeShortName);
63 await _context.SaveChangesAsync();
65 return RedirectToPage("./Index");