razor-pages

Updating related entities

﹥>﹥吖頭↗ 提交于 2019-12-24 06:30:28
问题 AppUser identity model: public virtual ICollection<UserPhones> UserPhones { get; set; } Using Razor Pages, I call a partial view, like so: @await Html.PartialAsync("_NameAndID", Model.AppUser) PageModel: [BindProperty] public AppUser AppUser { get; set; } public IActionResult OnGet() { AppUser = _userManager.Users //.Include(x => x.UserAddresses) //OMITTED BC USING LAZY LOADING .SingleOrDefaultAsync(x => x.UserName == _httpContext.HttpContext.User.Identity.Name).Result; return Page(); }

ASP.NET Core Identity - LoginPartial broken after scaffolding identity

一笑奈何 提交于 2019-12-24 02:59:07
问题 I created a new Project from the VS 2017 template (web application with individual user accounts). This adds the ASP.NET Core Identity as default UI (using the UI from a nuget). services .AddDefaultIdentity<IdentityUser>() .AddEntityFrameworkStores<ApplicationDbContext>() .AddDefaultTokenProviders(); With this nuget everything works as expected. Especially the loginPartial which shows the username once a user has logged in and shows the Login Button right after clicking logout. Once I

Pagination and Pages conflict - ASP.Net Core Razor Pages conflicts with MVC controller method pagination

一个人想着一个人 提交于 2019-12-23 22:26:16
问题 In an ASP.Net Core 2.1 with Angular 6 spa project, I return a paginated list of users using this AccountController.cs method: [HttpGet("users")] [Produces(typeof(List<UserViewModel>))] public async Task<IActionResult> GetUsers() { return await GetUsers(-1, -1); } [HttpGet("users/{page:int}/{pageSize:int}")] <---- conflicts here [Produces(typeof(List<UserViewModel>))] public async Task<IActionResult> GetUsers(int page, int pageSize) { var users = await _accountManager.GetUsersLoadRelatedAsync

How to make Login page as a default route in ASP .NET Core 2.1?

*爱你&永不变心* 提交于 2019-12-23 09:29:30
问题 I am beginner in ASP .NET Core 2.1 and working on project which is using ASP .NET Core 2.1 with individual authentication. I want to make my login page as my default route instead of Home/Index: routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); Any help how can i change it as ASP .NET Core 2.1 as Login is now used as a razor page instead of MVC Action View. 回答1: Use this in ConfigureServices method. services.AddMvc().AddRazorPagesOptions(options=> {

How to handle model binding of Complex Type with List of interfaces and nested list of interfaces with possibly no values

北城以北 提交于 2019-12-23 04:36:32
问题 I have successfully(maybe not elegantly) created a model binder that will bind a List of Interfaces on post. Each interface has separate properties and some have a nested List of another interface. The list of interfaces get displayed correctly in the view and so do the nested list items. On post everything works, the custom model binders get called and the correct types get built. The issue that has me stuck is that if a nested List of interfaces has no items to display, on post back the

Locate Razor Pages in another assembly

泄露秘密 提交于 2019-12-23 03:44:10
问题 I want to locate My Project Razor Pages in another assembly. for doing this I write following code: public void ConfigureServices(IServiceCollection services) { var adminAssembly = Assembly.Load(new AssemblyName("App")); services.AddMvc().AddApplicationPart(adminAssembly).AddRazorOptions(options => { var previous = options.CompilationCallback; options.CompilationCallback = context => { previous?.Invoke(context); context.Compilation = context.Compilation.AddReferences( MetadataReference

Asp.net core razor pages load partial page

試著忘記壹切 提交于 2019-12-21 21:42:27
问题 I use asp.net core 2 new feature Razor pages. in the _layout.cshtml. <body> <div> @await Html.PartialAsync("_LayoutHeader") <div class="row"> <div> <div class="row"> @RenderBody() </div> </div> </div> the _layoutHeader.cshtml is page with code behind. @page @using Microsoft.AspNetCore.Identity @model Yiko.Ent.WebRazorPages.Pages._LayoutHeaderModel and @RenderBody will load index.cshtml with pagemodel. @page @model Yiko.Ent.WebRazorPages.Pages.Home.IndexModel @{ ViewData["Title"] = "Home"; }

Razor Pages, form page handler not working with GET method

懵懂的女人 提交于 2019-12-21 12:10:36
问题 I have a small ASP.NET Core 2.1 Razor Pages project. I'm making a simple list display page with a basic search functionality. In my model, I have 4 page handlers (2 of them are added for debug purposes): public async Task OnGetAsync() { Posting = await _context.Postings .Include(p => p.ItemDetails).Include(p => p.Owner).ToListAsync(); } public async Task OnPostAsync() { Posting = await _context.Postings .Include(p => p.ItemDetails).Include(p => p.Owner).ToListAsync(); } public async Task

Unable to resolve service for type 'Microsoft.Extensions.Logging.ILogger`1[WebApplication1.Startup]'

倾然丶 夕夏残阳落幕 提交于 2019-12-21 04:49:06
问题 I created an ASP.NET Core 3.0 Web Application with the default template in Visual Studio 2019 Preview 2.2 and tried to inject an ILogger in Startup: namespace WebApplication1 { public class Startup { private readonly ILogger _logger; public Startup(IConfiguration configuration, ILogger<Startup> logger) { Configuration = configuration; _logger = logger; } // ... } } In Program.cs I also call the ConfigureLogging() method: namespace WebApplication1 { public class Program { public static void

Download file to browser using .NET Core Razor Pages

若如初见. 提交于 2019-12-21 02:38:13
问题 Using ASP.NET Razor Pages, I am trying download a file to the browser. From the Page(html), using a link like this works fine: href="/DownloadableFiles/testB.csv" download="newname">Download Link However, I want to initiate the download from the code-behind or ViewModel so it can be dynamic as to what the filename is, I also need to inspect the file first, etc. In ASP.NET MVC core, (not RazorPages) you can download a file in code using: return File(memory, GetContentType(path), Path