我用两个ActionResult制作了一个控制器。 GetData将对象List返回到View GAStatistics.cshtml。我已经向GASTatistics.cshtml添加了一个@ Html.DropDownList,我想用GetData - ActionResult和GetData.cshtml填充这个下拉列表。
我还有一个名为GAStatisticsListModel的列表模型,它包含DateTime StartDate,EndDate和List AvailableGAStatistics。我想我必须添加视图" GetData.cshtml"或ActionResult GetData AvailableGAStatistics。
我还制作了一个ListModel并在视图中添加了一个DropDownList。如何将GetData.cshtml作为项添加到菜单中?
我最好的猜测是我需要创建一个ActionResult,它将CreateCompaniesList添加到GAStatisticsListModel中的model.AvailableGaStatistics,但我不知道。
控制器:
public class GAStatisticsController : Controller
{
//GET: /ShopStatistics/
public ActionResult GetData() // <-- this result as a menu item
{
return Json(CreateCompaniesList(), JsonRequestBehavior.AllowGet);
}
public ActionResult GAStatistics()
{
return View(new GAStatisticsListModel());
}
private IEnumerable<GAStatistics> CreateCompaniesList()
{
//SOME CODE........................
List<GAStatistics> ListGaVisitors = new List<GAStatistics>();
foreach (var row in d.Rows)
{
GAStatistics GaVisits = new GAStatistics(row[0], row[1]);
ListGaVisitors.Add(GaVisits);
}
return ListGaVisitors;
}
}
(我想将ActionResult GetData添加到AvailableGAStatistics) 的ListModel:
public class GAStatisticsListModel : BaseNopModel
{
public GAStatisticsListModel()
{
AvailableGAStatistics = new List<SelectListItem>();
}
[NopResourceDisplayName("Admin.ShopStatistics.List.StartDate")]
[UIHint("DateNullable")]
public DateTime? StartDate { get; set; }
[NopResourceDisplayName("Admin.ShopStatistics.List.EndDate")]
[UIHint("DateNullable")]
public DateTime? EndDate { get; set; }
[NopResourceDisplayName("Admin.GAStatistics.GAStatistics.AvailableGAStatistics")]
public int GAStatisticsId { get; set; }
public List<SelectListItem> AvailableGAStatistics { get; set; }
}
查看:
@model GAStatisticsListModel
@using Nop.Admin.Models.GAStatistics;
@using Telerik.Web.Mvc.UI;
@using Nop.Admin.Controllers;
@{
ViewBag.Title = "GAStatistics";
Layout = "~/Administration/Views/Shared/_AdminLayout.cshtml";
}
<table class="adminContent">
<tr>
@*<td>@Html.Action("GAnalyticsService", "GAStatistics")</td>*@
</tr>
<tr>
<td class="adminTitle">
@Html.NopLabelFor(model => model.StartDate):
</td>
<td class="adminData">
@Html.EditorFor(model => model.StartDate)
</td>
</tr>
<tr>
<td class="adminTitle">
@Html.NopLabelFor(model => model.EndDate):
</td>
<td class="adminData">
@Html.EditorFor(model => model.EndDate)
</td>
</tr>
<tr>
<td class="adminTitle">
@Html.NopLabelFor(model => model.GAStatisticsId ):
</td>
<td class="adminData">
@Html.DropDownList("GAStatisticsId", Model.AvailableGAStatistics)
</td>
</tr>
</table>
如果我试试这个:
public ActionResult GAStatistics()
{
var model = new GAStatisticsListModel();
model.AvailableGAStatistics = CreateGAStatisticsReport();
return View(model);
}