last day (15 days later) » 

8:07 AM
2
A: How can I use the value of a jQuery variable in c# (cshtml)

Xinran ShenHere is a simple demo about how to achieve your goal, Hope it can help you solve this issue. Because you don't provide your model design, So here is my model in demo: public class Templates { public string Item1 { get; set; } public string Item2 { get; set; } } For test c...

 
Hi @citr0q, Have this answer solved your issue?
 
It looks very good! THANK YOU VERY MUCH! But what is "templates" in the backend snipped? When I copy and paste it, an error occurs....
 
Because I hard code in my demo like List<Templates> templates = new List<Templates>{.......}, It is just the name of List<Templates>. You can just replace it in your demo.
@citr0q, Have you solved this issue now?
 
nope i dont know what I should use there
 
You just need to use your original code var templatee = Model.Templates.Distinct().ToList(); var currentTemplate = templatee.SingleOrDefault(x => x.Item2 == selectedIndex).Item1; in backend, The backend i posted just use the value(selectedIndex) passed from frontend to select data in database, So you just need to replace it to your original query code.
 
8:07 AM
Whe I do this i get a System.NullReferenceException: "Object reference not set to an instance of an object."
 
I see you mark this answer, Have you solved it now?
 
No im still stuck with the exception but i think it is a very good answer and it makes sense
Do you have an idea how to solve this exception?
 
which code caused this exception?
 
        var templatee = templatesVM.Templates.Distinct().ToList();
it says "templatesVM" was "null"
 
i don't know what templatesVM is, you don't provide it.
 
8:12 AM
public class TemplatesVM
{
public List<(string, string)> Templates { get; set; }

}
it is the same as in the cshtml
 
oh, try to change it to public List<(string, string)> Templates { get; set; } = new List<(string, string)>();
 
the @model
its still null
but maybe i just dont know how to set it right. i just set it like this: private readonly TemplatesVM templatesVM;
ofc its null but do you know how to set it
 
can the dropdownlist page rendered successfully?
 
yes
but when i change the dropdown the exception occure
 
oh, I know the result, you don't pass any data into templatesVM, So it is null
 
8:19 AM
then how do i pass the data into it?
 
Are you using database with ef core?
Where you save the data about templatesVM?
 
I dont think so but im not sure
VM is just the viewmodel. the real model is TEMPLATE and i save it in database
 
So, you need to select the data of TEMPLATE from database, and use this data to do query
 
I GO IT
YEEEESSSS
THANL YPU SO MUCH MY FRIEND
THANK YOU*
 
welcome
 
8:30 AM
I just used the getTemplates method to get data. im so stupid
 

last day (15 days later) »