如何使用 ASP.NET MVC 创建仪表板用户界面?

发布于 2024-07-08 07:11:32 字数 356 浏览 8 评论 0原文

我目前正在使用 ASP.NET MVC 构建一个应用程序。 数据输入页面相当容易编码,我只需为我的业务对象类型的页面创建模型:

namespace MyNameSpace.Web.Views.ProjectEdit
{
    public partial class MyView : ViewPage<Project>
    {
    }
}

我正在努力找出实现类似仪表板的界面的最佳方法,其中包含独立的部分,使用ASP.NET MVC,每个部分的模型会有所不同吗? 我假设每个部分都是 MVC 用户控件。

另外,我怎样才能让每个部分都是可测试的?

I am currently building an application using ASP.NET MVC. The data entry pages are fairly easy to code, I just make the Model for the page of the type of my business object:

namespace MyNameSpace.Web.Views.ProjectEdit
{
    public partial class MyView : ViewPage<Project>
    {
    }
}

Where I am struggling is figuring out the best way to implement a dashboard like interface, with stand-alone parts, using ASP.NET MVC, where the Model for each part would be different? I'm assuming that each part would be an MVC user control.

Also, how could I make it so each part is testable?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

情定在深秋 2024-07-15 07:11:32

我认为用户控件可能是可行的方法。 我不确定可测试性的担忧是什么。 您应该能够测试您的控制器是否提供了正确的视图数据 - 因为您将有多个模型,每个模型都可能存储在单独的视图数据项中,而不是将它们聚合在单个模型中。 聚合在单个模型中也是可能的,尽管可能更脆弱。 每个控件只需要检查特定的视图数据项,而不是特定于特定的模型。 您可以通过执行以下操作来近似每个视图页面上的模型变量:

<% MyUserControlModel model = ViewData["MyUserControlModel"]
         as MyUserControlModel; %>

<div id="myUserControl_dashboard" class="dashboard">
   Name: <%= model.Name %><br />
   Count: <%$ model.Count %>
</div>

如果您需要测试您的视图,那么您可能已经在使用 Selenium 或其他一些 Web 测试框架。 我认为这些不会关心页面的构建方式,并且您应该能够像往常一样构建测试。

I think that user controls is probably the way to go. I'm not sure what the concern is about testability. You should be able to test that your controller is providing the right view data -- since you'll have several models each of these will probably be stored in a separate view data item, rather than aggregating them in a single model. Aggregating in a single model is also possible, although probably more brittle. Each control would just need to check for a particular view data item, rather than being specific to a particular model. You could approximate the model variable on each view page by doing:

<% MyUserControlModel model = ViewData["MyUserControlModel"]
         as MyUserControlModel; %>

<div id="myUserControl_dashboard" class="dashboard">
   Name: <%= model.Name %><br />
   Count: <%$ model.Count %>
</div>

If you need to test your view, then you're probably already using Selenium or some other web testing framework. I don't think that these would care how the page was constructed and you should be able to construct your tests pretty much like you always do.

不必你懂 2024-07-15 07:11:32

查看 MVC-Contrib 中子控制器的概念 http://www.codeplex.com/MVCContrib。 基本上,您对部分内容运行完整请求,然后在现有代码中所需的位置显示该部分内容。

或者,您可以查看这篇文章: http:// /blog.codeville.net/2008/10/14/partial-requests-in-aspnet-mvc/

Check out the notion is sub-controllers in MVC-Contrib http://www.codeplex.com/MVCContrib. Basically you run a full request to a partial then display that partial where you want in your existing code.

Alternatively you can check out this post: http://blog.codeville.net/2008/10/14/partial-requests-in-aspnet-mvc/

燃情 2024-07-15 07:11:32

Codeplex.com 有一个开源项目“DotNet.Highcharts”。 该项目提供了一个 ASP.NET 控件,它包含优秀的(免费供个人使用)Highcharts 图表库。 下载部分包含一个示例 MVC3 项目。

URL:http://dotnethighcharts.codeplex.com/

我在 CodeProject.com 上发布了一篇文章,其中包括可下载的 VS2012 解决方案和一些示例 C# 代码。 不过,我在示例中使用了 Web 表单模板,而不是 MVC。 仪表板的大部分内容是使用 JavaScript 库、HTML 和 HTML 来完成的。 CSS。 我提供了一些示例 C# 代码来演示 C# 中的数据检索,然后将其与 JavaScript 代码合并以呈现众多仪表板图表之一。

Codeplex.com has an open source project "DotNet.Highcharts". This project provides an ASP.NET control that wraps around the excellent (free for personal use) Highcharts charting library. that includes a sample MVC3 project in the downloads section.

URL: http://dotnethighcharts.codeplex.com/

I have posted an article on CodeProject.com that includes a downloadable VS2012 solution and some sample C# code. However I use a webform template in my example, not MVC. The bulk of the dashboard is done using JavaScript libraries, HTML & CSS. I have included some sample C# code to demo data retrieval in C# which in then merged with JavaScript code to render one of the many dashboard charts.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文