C
C#17mo ago
BekirK

✅ About ModelState in MVC

Hello, I got stuck at a point about ModelState in my work. From a Create method, I Bind the Product model with "Name", "Price" and "Stock" and submit it with the form (only these values). Then I verify with ModelState.Isvalid, but because the "Id and UserId" fields in the Product model are null, it says invalid and returns "false". I don't want it to evaluate them because they won't come from the form (e.g. Id will automatically fill in the SQL Server). Can you help me how to proceed at this stage? (NOTE: I can make the UserId nullable and bypass it, but if I make the Id nullable I get the error "... when IDENTITY_INSERT is set to OFF".)
13 Replies
Unknown User
Unknown User17mo ago
Message Not Public
Sign In & Join Server To View
BekirK
BekirK17mo ago
Okay. When I'm available, I'll do the Dto-related transactions and get back to you. A simple project that I created for learning the Strategy pattern. This is how I did it to change the runtime on 2 separate servers. kshkshskhhsk
Unknown User
Unknown User17mo ago
Message Not Public
Sign In & Join Server To View
BekirK
BekirK17mo ago
Yes. I mean that. Thanks
Unknown User
Unknown User17mo ago
Message Not Public
Sign In & Join Server To View
BekirK
BekirK17mo ago
I'm following a udemy course so
Unknown User
Unknown User17mo ago
Message Not Public
Sign In & Join Server To View
BekirK
BekirK17mo ago
The course is about design patterns. Therefore, the trainer only focuses on this. I'm also not a complete judge about the database. Yes you are right.
Unknown User
Unknown User17mo ago
Message Not Public
Sign In & Join Server To View
Anton
Anton17mo ago
also the strategy pattern doesn't need any of this web setup learn it separately
Unknown User
Unknown User17mo ago
Message Not Public
Sign In & Join Server To View
BekirK
BekirK17mo ago
It was better for me if you explained everything directly. not rude at all Thank you for the information and your time. I will search about what you said.
Accord
Accord17mo ago
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.