MVC .net 适合我的项目类型吗?
经过无数个小时的研究(创建一些演示项目、观看网络研讨会等),我觉得 MVC .net 非常适合 90% 的 Web 应用程序类型,但不适合我的。
基本上我有一个仪表板应用程序,我在许多不同的图形/图表中显示大量信息(全部在同一屏幕上)。如果我更改页面上控件的状态(例如日期范围),我希望所有图形/图表都能相应更新。
这在使用带有 ajax 更新面板的用户控件的 Web 表单中相当简单,但我还没有在 MVC 中看到“良好”的简单实现,而无需在 JQuery / Javascript 代码中完成大部分繁重的工作。
MVC 中的大多数回发示例都涉及表单提交(我们的仪表板上没有任何表单),或者涉及从视图到视图的导航(我也不想这样做)。我能想到的最接近我们需要的是 MVVM 框架,但几个月内我们不会迁移到 Silverlight。
我是否认为 MVC 是错误的,我是否错过了一个主要博客/教程没有涵盖的简单示例?有什么想法吗?
After countless hours researching (creating a few demo projects, viewing webinars etc..) I feel like MVC .net works great for 90% of the web application types out there, but not for mine.
Basically I have a dashboard application where I'm displaying large amounts of information in many different graphs / charts (all on the same screen). If I change the state of a control on the page, say a date range, I would like all of the graphs / charts to update accordingly.
This is fairly trivial in webforms using usercontrols with ajax update panels, but I've not seen a 'good' simple implementation in MVC without doing most of the heavy lifting in JQuery / Javascript code.
Most of the examples of post backs in MVC involve a form submission (we don't have any forms on our dashboard) or it involves navigation from view to view (which I don't want to do either). The closest thing I can relate what we need to would be an MVVM framework but we won't be moving to Silverlight for a few months.
Am I thinking of MVC wrong, am I missing such a simple example that the major bloggers / tutorials don't cover it? Any thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
不,你没有错。在许多方面,MVC 更接近“金属”。 Web 表单使此类事情在代码方面变得“微不足道”,但通常只是使其在带宽方面效率极低。
MVC 采用了不同的方法;它们迫使您注意到手动执行的低效做法。为了解决这种复杂性,必须将 jQuery 和 AJAX 添加到 MVC 中。
听起来您确实需要一个 Silverlight 解决方案。
No, you're not wrong. In many ways, MVC is closer to the "metal." Web Forms makes things like this "trivial" in terms of code, but usually only by making it extremely inefficient in terms of bandwidth.
MVC takes a different approach; they force you to notice inefficient practices by doing it manually. jQuery and AJAX must be added to MVC for this kind of complexity.
It does really sound like you need a Silverlight solution.
如果您的图表/图形控件是经典的 ASP.net 控件,那么最好坚持使用经典的 ASP.net 应用程序。某些 ASP.net 控件不能很好地与 MVC 配合使用。
If your chart/graph controls are classic ASP.net controls then it might be best to stick with a classic ASP.net application. Some of the ASP.net controls don't work too well with MVC.
MVC 应该可以简化您的开发。如果没有,请勿强行使用。如果 WebForms 更符合您的要求,请坚持使用。
MVC is supposed to ease your development. If it doesn't, dont use it by force. Stick to WebForms if they fit your requirements better.
您所描述的仪表板应用程序听起来 ASP.NET MVC 并不是一个糟糕的选择。
图表 - 您可以将 Microsoft Charting 控件与 ASP.NET MVC 结合使用 - 操作方法如下。
表格和视图 - 我可以想象您会将这些日期选择器包装在表单标签中。每个网格或图表在 ViewModel 上都有一个集合或某种类型的成员变量。为每个网格创建一个部分视图,将适当的数据作为 ViewModel 发送给它,然后简单地
foreach
构建一个table
或ul
来显示您认为合适的表格数据。The dashboard app as you describe it doesn't sound like ASP.NET MVC would be a BAD choice.
Charts - you can use the Microsoft Charting controls with ASP.NET MVC - here's how.
Forms & Views - I can imagine you'd wrap those datepickers in form tags. Each grid or chart would have a collection or member variable of some kind on the ViewModel. Create a partial view for each grid, send the appropriate data to it as the ViewModel, and simply
foreach
to build atable
orul
to display your tabular data as you see fit.正如其他人所说,MVC 不一定比 WebForms 更好,您应该使用最适合您的项目需求的东西。不要仅仅因为 MVC 是最新最好的就使用它。
尽管如此,由于 ASP.NET MVC 和 Webforms 使用相同的运行时环境,因此您可以创建一个 ASP.NET MVC 项目并在需要时在该项目中使用 Webforms。这样,您就可以充分利用这两个世界。
As others have said, MVC is not necessarily better than WebForms, and you should use what is best for your project needs. Don't use MVC just because it is the latest and greatest.
With that said, because ASP.NET MVC and Webforms use the same runtime environment, you could create an ASP.NET MVC project and use Webforms within that project when needed. That way, you can get advantage of both worlds.
感谢大家的回复!我非常感激。
我找到了一种方法,通过将 AJAX 回发合并到特定的 div 标签,使 MVC 在周末针对我的用例非常有效地工作。我添加了一些 AJAX 扩展方法来处理按钮/下拉菜单等(也使用一点 JQuery),以便它们调用特定的控制器并返回仅在指定的 div 中更新的视图。
可能是 MVC 的基础知识,但是一旦我戴上 javascript 帽子(并且不再从 Webforms 的角度来看这个),它实际上就变得很有意义。还合并了 McvContrib 和 Ninject 到我的代码库中减轻了我预见到的一些痛苦。我强烈建议任何研究 MVC 的人都检查一下这两个工具(尽管 Ninject 并不完全是 MVC)。
再次感谢。
^t
Thanks for everyone's response! I greatly appreciate it.
I found a way to make MVC work very effectively over the weekend for my use case by incorporating AJAX postbacks to particular div tags. I added a few AJAX extension methods to handle buttons / drop downs etc (also with a little JQuery) so that they call a particular controller and return a view updated in only specified divs.
Probably the basics of MVC, but once I put on my javascript hat (and stopped looking at this from a webforms perspective) it actually made a lot of sense. Also incorporating McvContrib and Ninject into my code base eased quite a few pains that I foresaw. I would highly recommend anyone looking into MVC to check out those two tools (even though Ninject isn't exclusively MVC).
Thanks again.
D^t