Alizer
asp core form tag helpers but the router has dynamic route
i have this form
now the endpoint it points to is below
but for some reason it points to the wrong route, the generated html is
as you can see it points to
/DocumentGenerations/GenerateCheque
which is wrong, but this is probably becaus of the {payrollHistoryId}
in the route, how would i fix this?8 replies
mapping a dynamic object to an existing object and only map properties that exist in the source obj
I need help with patching an object in ASP Core, on my api i only send a partial data of the object i want to update, i looked into
JsonPatchDocument<T>
but the syntax is too complicated compared to what my competitors do with their API, what i want here is just for my customers to send a json with the properties and values they want to change and that's it, let's say i have an object like
and in my API I only want to update specific properties, so I decided to take a dynamic object in my action
in my update method i have this code
now, for some reason existingCar
has all properties turned to their default or null values, how should i fix this? is there an alternative library for doing this11 replies
Scaffold Not Working because `dotnet-aspnet-codegenerator.exe` uses old C# version
I need help with scaffolding identity my C# project, I get this error whenever I scaffold
D:\ProjectFolder\ClientAction(81,37): error CS1002: ; expected
and I look into the line that causes this and I found it it's caued by the new required
keyword
The project builds successfully in dotnet rider, no problems at all, however when it runs dotnet-aspnet-codegenerator.exe
to scaffold I get a lot of errors, I'm thinking it's caued by dotnet-aspnet-codegenerator.exe
using an old c# version, currently I use .net 7.0
Now my problem is that I have around 100+ properties using required
and I needed to scaffold the Identity to edit the register and login pages, how do I get around this?5 replies
❔ I need help making a `diff` of 2 objects of the same class
I have a complex class like below
Now, I have 2 instances of this class
Person
and I want to get the differences between both, my problem is the Person
class is a really complex class, it has around 20+ properties, some properties are collections, I made a class like below to record the differences
my question is, how do I start with this? if there is a library that does this automatically I would use it4 replies
❔ Return PartialView with ``for`` attribute
I have a complex <form> in my .cshtml file and I want to simplify it more, now I have this original code, this is inside the <form>
now instead of doing a foreach loop I want to add these <partial/> views with the click of a button, I plan on doing this by making a controller return the partial view and I'll just append it to the parent div via an ajax call using jquery, I have the following action in the controller below
this returns the partial view but how do I add
for="parentAssistance[assistanceIndex].Assistances[assistanceDataIndex]"
in the PartialView? Is this even possible? If not could there be another way around it?7 replies
✅ Retain form tag helper names inside partial view
I want to retain a form tag helper's name inside a partial view, I have a massive form model with lots of nested objects, below is just a simplified version of what I wanted to do
I have a form below, this works because Name.FirstName is being handled correctly by ASP automatically setting the name of the <input/> tag, my controller parses this correct into a Member object
but since my form is massive, I wanted to split it to multiple sections, now I put the Name property inside another partial view like below
and below is the main form's .cshtml file
and for some reason this breaks ASP's automatically set name for the <input/> tag, it just sets the input's name to FirstName when it should be Name.FirstName, how do I fix this?
3 replies
How do I pass data from my partial view to my main layout in ASP Core?
I have this code in my partial view:
Now I want to pass this data to my main layout.
What I want to do here is to set
ViewData["LessonTitle"]
in my partial layout and get that data in my _Layout.cshtml
but I get the error NullReferenceException: Object reference not set to an instance.
specifically on the <h1>@ViewData["LessonTitle"]</h1>
line, if I remove that line I don't get any error at all so I believe I can't pass data from partial view to layout via ViewData....? If I can't, how do I pass data from my partial to my main layout?1 replies
❔ what the proper way to check if ``dynamic`` has a specific property?
I have this code below
now I'm passing this as a
@model
to a partial view
how do i properly check if modelObject
has a property named Count? I searched for solutions online and most require me to turn it into a Dictionary BUT I DONT WANT TO DO THAT!! casting it to dictionary is just....redundant and doesn't feel right, anyways, is there a proper way to do it?16 replies
❔ How do I use a .cshtml (or Razor View) from a class library?
I wanted to make a modular ASP Core project, I wanted to make some kind of 'plugin system' for me project, basically some Razor views will be stored in class libraries, but currently I don't know how to do it, I followed the instruction at the Microsoft docs and Controllers work, I was able to add a controller class to my library and make it return a 200 OK on a specific route, however Razor views don't work, the following below is my code for importing .dll files
2 replies
❔ Any good persistent data solution for .net core 6 c#?
Back in .NET framework I use settings and the
Properties.Settings.Default
namespace to store data in just about a line of code but looks like I cannot use it with the new .net core 6, is there like a library or just a good way of storing persistent user data in .net core? something that doesnt require me to use a database12 replies
❔ how to get the current selected text from any window just like how clipboard does it?
I want to simulate Ctrl + C without pressing Ctrl + C, basically able to read any selected text from any window be it a browser, notepad or word, most solutions I found online requires me to call SendKeys to do Ctrl + C every mouse release but some programs (such as VLC media player) performs a different action if Ctrl + C is pressed, and hell, I have no idea if text is even being selected in the first place, so currently my question is, how do I simulate clipboard copy without pressing Ctrl + C?
6 replies
how to add a table to an existing ef core database created using EnsureCreated()?
I have an existing SQLite database (30GB in size) which was created using
EnsureCreated()
, now I need to add a table which I tried using migrations (I passed dotnet ef database update
) on the command line but it causes Microsoft.Data.Sqlite.SqliteException (0x80004005): SQLite Error 1: 'table "AspNetRoles" already exists'.
error, I did a lot of research and it seems like I needed to create the database via migrations.
How do I add a table when the ef core database is created via EnsureCreated()
? Do I have to create the db via migrations and fill it with data from the existing db? can there be a way in which I can add the table be it via code?4 replies