TrustyTea
TrustyTea
CC#
Created by TrustyTea on 4/25/2024 in #help
Blazor Project Hierarchy
Ahhh okay thanks for the help! I'll read through that and decide what to do next 🙂
5 replies
CC#
Created by TrustyTea on 4/25/2024 in #help
Blazor Project Hierarchy
Yeah sorry, I kinda have 2 questions going there. The main problem I'm having is trying to get my /Account/ pages to work with an Interactive render mode. I'm just reading the comments on this AccountsLayout.razor that came with the template that says
// If this code runs, we're currently rendering in interactive mode, so there is no HttpContext.
// The identity pages need to set cookies, so they require an HttpContext. To achieve this we
// must transition back from interactive mode to a server-rendered page.
// If this code runs, we're currently rendering in interactive mode, so there is no HttpContext.
// The identity pages need to set cookies, so they require an HttpContext. To achieve this we
// must transition back from interactive mode to a server-rendered page.
So it's then transitioned into a server-rendered page, and all my buttons and interactive components stop working because of that transition. I tried to restart and make a new project with the Auto rendering mode, but I was having the reference issues. I'm either trying to find a way to fix that referencing issue, or find a way to keep my interactive render mode while keeping that HttpContext.
5 replies
CC#
Created by TrustyTea on 4/24/2024 in #help
Blazor Problems with Layouts
Ahh okay, thanks! I’ll read up more on that
3 replies
CC#
Created by TrustyTea on 2/13/2024 in #help
Minimal API : Model / DTO Help
Sweet thank you! 😄
27 replies
CC#
Created by TrustyTea on 2/13/2024 in #help
Minimal API : Model / DTO Help
I see 🤔 , yeah that makes sense. I also need to practice and learn some more LINQ. Thanks for the help! Just knowing that I should be using DTOs as part of my responses is enough of a direction to get me started on it. If I have some more questions, am I ok to come back to this thread?
27 replies
CC#
Created by TrustyTea on 2/13/2024 in #help
Minimal API : Model / DTO Help
Oh ok, is it because I have this line? Tags = b.Tags.Select(t => new TagDTO { Id = t.Id, Name = t.Name }).ToList(), Or the .Select() right below the .Include()?
27 replies
CC#
Created by TrustyTea on 2/13/2024 in #help
Minimal API : Model / DTO Help
Ah oops that's a copy error :P, that's not actually there sorry
27 replies
CC#
Created by TrustyTea on 2/13/2024 in #help
Minimal API : Model / DTO Help
So I'd be creating a new DTO in the requests, and populating it with the data from the database? I had something like this before I went to what I have now:
private static async Task<IResult> GetBlogs(ApplicationDbContext db) {
var blogDtos = await db.Blogs
.Include(b => b.Tags)
.Select(b => new BlogDTO
{
Id = b.Id,
Title = b.Title,
Summary = b.Summary,
Body = b.Body,
CreatedOn = b.CreatedOn,
Tags = b.Tags.Select(t => new TagDTO { Id = t.Id, Name = t.Name }).ToList(),
AssociatedProjectId = b.AssociatedProjectId
})
.ToListAsync();
return Results.Ok(blogDtos);
}
private static async Task<IResult> GetBlogs(ApplicationDbContext db) {
var blogDtos = await db.Blogs
.Include(b => b.Tags)
.Select(b => new BlogDTO
{
Id = b.Id,
Title = b.Title,
Summary = b.Summary,
Body = b.Body,
CreatedOn = b.CreatedOn,
Tags = b.Tags.Select(t => new TagDTO { Id = t.Id, Name = t.Name }).ToList(),
AssociatedProjectId = b.AssociatedProjectId
})
.ToListAsync();
return Results.Ok(blogDtos);
}
I'll have to go back to this and figure it out now that I know to use DTOs as outgoing too. IIRC I wasn't getting the Tags in the response, just the IDs
27 replies
CC#
Created by TrustyTea on 2/13/2024 in #help
Minimal API : Model / DTO Help
Ahh okay, maybe I'll spend a little more time to learn about DTO's then. I thought they were for incoming objects and not for outgoing but it does make sense. Thanks for the tip on the .FirstOrDefaultAsync() too!
27 replies
CC#
Created by TrustyTea on 2/13/2024 in #help
Minimal API : Model / DTO Help
I was running into cycles and thought that might help. It might have been left over from a few things I was trying and forgot to remove it after I changed up the Model & DTO.
27 replies