开发者

Is there any way to have Strongly Typed WebForms similar to MVC Views?

I've just recently fallen in love with the world of ASP.NET MVC, and one of my favourite parts is the fact that I can have Strongly Typed views, and when I submit the data to the Service layer, all I have to do is submit the model object and be done with it.

This is a stark contrast to a relatively large sc开发者_Python百科ale WebForms app I build last year. The problem with this app was that the client needed (wanted) over 150 fields per table for two of their tables (increasingly frustrating was the fact that the field "names" were numbers, but that's another story).

What I found myself doing (on many forms) was the following.

Dim bfs As New BusinessForSale

With bfs
    .123 = txt123.Text
    .124 = txt124.Text
    ''# etc
    ''# etc
    ''# 148 more bloody times
End With
''# Yes it was that frigging frustrating.

Then I could submit the bfs object to the database.

Now in MVC, the model takes care of all of that for me.

Was I doing that completely wrong? Is there a way (not that I'll ever go back to WebForms, but just for my own knowledge) to submit a form "model" to the database instead of setting each parameter individually like that? It was seriously the most painful programming experience I've had simply because of the monotony.


You could essentially build those components for web forms; they don't exist in the existing framework as is. I had the same idea, why write all that code when some reflective process can do it for me. I've been trying to work that into my MVP framework for Nucleo (http://nucleo.codeplex.com), and that is going to be one of my focuses (even the AJAX postbacks too). But I digress, sorry for the plug.

Anyway, you could build the reflective piece that matches the control ID to the name of a property in a class. It can't be as automatic as you see in ASP.NET MVC (because of the core differences in the plumbing), but it could be something as simple as a method call that kicks off that process.

HTH.


This could give you some ideas on how to implement something similar to strongly typed views.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜