❔ Session Variables
Storing what a user selects from a dropdown to a session variable but it gives a null error which should not be. looked for the error i know it lies here. tried for 2 days but no success. Just wondering is there another way to achieve my goal?
11 Replies
And you have enabled sessions in your startup?
Yes I have enabled sessions in my program.cs
So by the comment "//if i change studentid to 1 it works", you mean if you hardcode the value to 1, what exactly works? that the session variable is updated?
and if you don't, you get a null ref? on that line?
It displays the person's id or name in another controller/index
Okay, so there is nothing wrong with the session storage at all
Yes
its with your view model being weird
My first suggestion would be to actually stick to a naming standard, preferably the official C# one
Student_List
is a bad class name, and even worse considering it doesnt seem to actually represent a list. (Should be StudentList
, PascalCase).
studentss
has a typo in it.
int Studnentid
should be int studentId
, no typo, camelCase.
string studentname = studentss.StName;
should be string studentName = students.StudentName;
. camelCase local variable, no shortened name on the property.
then, use the debugger to actually inspect the value you are getting for studentss
. It appears to be null, which would mean the model binding failed or your frontend didnt actually send and form data.Student_list is a list in the model. Thank you so much i would work on the naming
Ohhh thank you
ah, but for a
[HttpPost]
endpoint, your method should take a single argument, a class object that represents the entire form payloadI understand, i would implement the changes and pray it finally
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.