开发者

Using the ASP.NET MVC dynamic model/viewbag only a bad idea?

As the sole developer of an app, would using a dynamic model, or the new ViewBag in ASP.NET MVC 3, exclusively be a bad idea (i.e., not building strongly typed classes)?

Currently, I have a strongly typed viewdata strategy that breaks the built-in html form helpers (like Html.TextBoxFor). My viewdata looks like this:

public class BaselineViewData {
  ...properties all views will need...
  public Area1ViewData Area1ViewData {get;set;}
  public Area2ViewData Area2ViewData {get;set;}
}

Some properties of the BaselineViewData are viewdata classes themselves. So far it's been great, but the form helpers don't work well. They output something like this:

@Htm开发者_Go百科l.TextBoxFor(u => u.Username) outputs

<input id="BaselineViewData.Area1ViewData.Username" ... />

With that naming, the built-in unobtrusive validation doesn't work.

I started this app with MVC 1, it's ported to MVC 3... but not taking advantage of all the benefits of MVC 3. So I decided I'm going to totally rewrite the app now, which will be much easier than it was then... now that there's so much handled for you. ;D


Weakly typed anything is more prone to errors than statically typed code.

You're throwing away one of C#'s greatest strengths by not using strongly typed views.


I'll be going with a hybrid strongly typed/viewbag viewdata strategy. I'll follow the example give in the accountmodels file in a default asp.net mvc 3 app.

Thanks!

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜