开发者

mvc 2.0 updatemodel and my ID Column

开发者 https://www.devze.com 2022-12-22 14:36 出处:网络
I have created a create view within my MVC 2.0 Application and by default it included a field for the integer ID Column.

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 someth开发者_如何学运维ing 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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消