DEV Community

Gustavo Sanchez Olea
Gustavo Sanchez Olea

Posted on

ASP.NET MVC

Ok, so first things first I’m generally new to ASP.NET MVC and although I’ve managed to get around things I’m starting to hit road blocks that require some more advanced help

Top comments (4)

Collapse
 
thetavog profile image
Gustavo Sanchez Olea

My problem is the the id value I give to the the property of my object does not get stored from my view, I have tried to pass it as a hidden property but either I’m doing it wrong or it’s not an actual thing you can and I have even attempted to add the object to my database pass the object to the the page and then update it again once it hits the post which again didn’t work or I’m doing incorrectly. Any help would be great. Thanks in advance

Collapse
 
vparab profile image
Vidisha Parab

Hey Gustavo,
Few questions

  1. You passing this value from controller to view or view to controller ?
  2. Where do you set the value of the id? You mentioned about database. Does it comes set as an identity field ? Also as long as the property names match there shouldn't be any problem in mapping those object properties in the POST method. Also ensure if the properties are properly encapsulated (getters and setters)
Collapse
 
thetavog profile image
Gustavo Sanchez Olea

I’m using SQL Server attached to a ASP.NET Core MVC Project in my [Get] Create method I passing an I’d from an index view. So far I’ve managed to pass it from the get to the create view and onto the post create but now I’m having problems where the table I have is not accepting the keys . I’m not sure what I’m doing

Thread Thread
 
vparab profile image
Vidisha Parab

Okay. So what I understood from this is

  1. There is no issue passing the data to and fro from view - controller (actions) since you said it is available in the post action "create"
  2. The issue is now when you try saving this object data to the SQL table

Are you using entity framework ?
About keys , if this key is marked as identity key in your sql table design, it cannot be modified explicitly through ef because it is generated by the table itself .You can set it to be ignored through the builder options.