views:

71

answers:

1

Hello,

I have created a create view within my MVC 2.0 Application and by default it included a field for the integer ID Column.

This is definitely a field i do not need.

If i remove the field and use updatemodel when trying to create the object in code, will something break because it doesnt see my ID column data being passed in, even though it is auto increment?

Also, i noticed that in the NerdDinner example, updatemodel was used and after that the repository.save method was called.

I thought that updatemodel would save the object to the database..why then call the .save method afterwards? Or have i missed something?

Any help with this would be appreciated.

Cheers

A: 

As I understand it, the UpdateModel method will blow away all data in the object. This is because MVC is round-trip based. Anything that goes out should come back if you need to keep state. See this question for more details.

A better way to handle this scenario in my opinion is to have an input model class as an Action parameter which is passed to a service call to update the domain entity in the DB. (Or this mapping code could be right in the action method if you really want.)

Also please be aware of the security vulnerabilities that could be introduced by binding directly to your DB model.

Ryan
Here is a post about the security vulnerabilities. http://www.codethinked.com/post/2009/01/08/ASPNET-MVC-Think-Before-You-Bind.aspx
Ryan