0
我试图从模型和从我的视图到我的控制器的字符串传递一个列表。我从Home控制器到Dashboard.cshtml的数据成功,但是当我尝试从模型传递一个列表到DetailController时,列表不会经过,但字符串TicketGroupName会。任何想法我做错了什么?MVC将多个参数传递给控制器,包括模型列表
Dashboard.cshtml
@model testlogin.Models.DashboardViewModel
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>@Model.AreaName</h2>
<table id="dashboardContainer" class="table">
<tr class="data-row-1">
<td class="tile text-center">
<a href="http://company.html"><img style="height: 125px" id="Image1" src="https://logo.jpg" /></a>
</td>
<td class="tile btn text-center">
<a href="@Url.Action("ShowTickets", "Detail", new { TicketList = Model.OpenNow, TicketGroupName = "Open Now" })">
<div>
<div class="row tile-head">
<h4>Open Now</h4>
</div>
<div class="row">
<h1><strong>@Model.OpenNow.Count</strong></h1>
</div>
</div>
</a>
</td>
</tr>
</table>
HomeController.cs
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
public ActionResult Dashboard(string AreaName)
{
full_area_name = "Test Area";
var dash = GetDashData(board_number); //Not including it here, but this method works
dash.AreaName = full_area_name;
return View(viewName: "Dashboard", model: dash);
}
}
DashboardViewModel.cs
public class DashboardViewModel
{
public List<TicketModel> OpenNow { get; set; }
}
DetailController.cs
public class DetailController : Controller
{
public ActionResult ShowTickets(List<TicketModel> TicketList, string TicketGroupName)
{
TicketViewModel vm = new TicketViewModel()
{
GroupName = TicketGroupName,
Tickets = TicketList
};
return View(vm);
}
}
个
TicketViewModel.cs
public class TicketViewModel
{
public string GroupName { get; set; }
public IEnumerable<TicketModel> Tickets { get; set; }
}
ShowTickets.cshtml
@model testlogin.Models.TicketViewModel
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
<div class="container">
<div>
<h1>@Model.GroupName</h1>
</div>
<table class="table table-striped table-bordered table-hover">
<tr>
<th>@Html.LabelFor(model => model.Tickets.FirstOrDefault().TicketNbr)</th>
<th>@Html.LabelFor(model => model.Tickets.FirstOrDefault().Company_Name)</th>
<th>@Html.LabelFor(model => model.Tickets.FirstOrDefault().Priority_Description)</th>
<th>@Html.LabelFor(model => model.Tickets.FirstOrDefault().Summary)</th>
<th>@Html.LabelFor(model => model.Tickets.FirstOrDefault().Last_Update)</th>
<th>@Html.LabelFor(model => model.Tickets.FirstOrDefault().OwnerOrCloser)</th>
<th>@Html.LabelFor(model => model.Tickets.FirstOrDefault().Date_Entered_UTC)</th>
<th>@Html.LabelFor(model => model.Tickets.FirstOrDefault().Date_Responded_UTC)</th>
<th>@Html.LabelFor(model => model.Tickets.FirstOrDefault().Date_Closed_UTC)</th>
</tr>
@Html.DisplayFor(x => x.Tickets)
</table>
</div>
您不应该通过GET操作单击链接传递列表。你应该再次在ShowTickets行为方法中得到它。 – Shyju
您不能使用'Url.Action()'将一个集合传递给GET方法(查看您生成的html)。您将需要传递集合中每个项目的每个属性作为查询字符串参数,这将是疯狂的,并且可能超过查询字符串限制)。在方法中再次获取集合。 –
我明白了。我会尝试并发布结果。谢谢你的帮助,你们俩! –