I am just wondering is there a way to bind coming request values to an object like we do in MVC in Web Pages.
Web pages has a simpler way to develop smaller websites than mvc. So I want to use razor web pages to develop websites now.
I used MVC for long time and there was automatic model binding based on conventions. And in any Action you can use TryUpdateModel()
method to bind request values on complex object for extra cool job.
There is a ModelBinders.Binders.DefaultBinder.BindModel()
method I can see in page but it needs two long parameters.
I am wondering is there a simple fast way for bind Request Parameters to C# object :)
Thx for help.
There is no Model Binding in the Web Pages framework. The framework was developed with novice developers primarily in mind and from the comments I saw from members of the project team at the time, they didn't think their target audience would understand or use strongly typed containers for data (business objects).
I needed something like this for a project I worked on, so I built my own very simple model binder. It's rough code that only handles simple types and hasn't been put through any kind of wringer, but it serves my purpose. You can use it for the basis of something more robust:
You would use it like this:
It's unclear at the moment how Web Pages will be incorporated into ASP.NET vNext. The ASP.NET team have talked about eliminating duplication across Web Pages, MVC and Web API, so hopefully that will result in Web Pages including Model Binding.