I've been working a lot this year with ASP.NET MVC 3 and C#. One of the things I really like about these technologies is the model binding. Let's say I have a data model called "User", a plain old C# class like this:
I can set that as a model for my view to use in the "Edit" controller like so:
And then I have "User" as the data model in my view. Here's what's awesome about it, let's say I need to accept edits of the user account, maybe they can fix their first or last name. I can pass that same User model from the previous page via a form into an Edit method that accepts that data model. I don't have to muck about with assigning the Request variables ( POST / GET ) to an object. All that is handled for me.
The ASP.NET MVC model binding will attempt to bind your model in these scenarios:
- If you have a form element on the page with an idenitical name to a property in the model
- If the url contains a key value pair from your routing that is identical to a property in the model
- If any REQUEST element has a name that is identical to a property in the model
- Otherwise, that property of the model will remain null
Plus, the ASP.NET MVC model binding will let you turn on/off model binding for various properties of the model.
PHP, or rightly, the many PHP frameworks really need to implement something like this. A few perform some pieces of this concept but I'm not aware of any that currently serve up the whole enchilada. What do you think?
No comments:
Post a Comment