【发布时间】:2017-05-08 20:07:03
【问题描述】:
我是 ASP.NET MVC 的新手。我有以下要求。
我需要在仪表板页面上动态显示饼图。我将在运行时决定饼图的总数。因此,我创建了饼图的部分视图和模型类。
首先,我将访问数据库并将数据填充到模型类中。我会找到任何教程。
控制器代码:
public ActionResult _Dashboard()
{
try
{
_dashboard = new Dashboard();
var model = _dashboard.GetToolsUtilization();
return View(model);
}
catch (Exception ex)
{
throw ex;
}
finally
{ }
}
工具类
public class Tools
{
public string toolName { get; set; }
public int used { get; set; }
public int free { get; set; }
}
_Dashboard.cshtml 页面
<div class="col-lg-12">
@foreach (var item in Model)
{
<div class="dash-unit col-lg-3">
Html.Partial("~/Views/Shared/toolGaugeInfo.cshtml", item)
</div>
}
</div>
ToolGauageInfo.cshtml
@model NETMS.DAL.ToolGauageInfo
我认为,部分视图页面很好。我将通过 ajax 调用在页面加载时调用控制器。现在,我不知道如何从控制器返回模型。
【问题讨论】:
标签: c# asp.net-mvc model-view-controller model partial-views