从mvc视图返回列表

时间:2011-03-01 22:39:09

标签: c# asp.net-mvc razor

当我查看我的DetailsReport(List<> filteredList)方法时,它的Count = 0.是否可以向控制器发送List或我的代码是否错误?

@Html.ActionLink("Print Results to Report",
                 "DetailsReport",
                 new {filteredList = Model} )

1 个答案:

答案 0 :(得分:0)

你的代码很糟糕。您不能像这样将模型作为Route的一部分传递。您需要序列化模型并将其作为请求有效负载的一部分或在查询字符串中发送。尝试这样的事情(不确定我的序列化是否与Razor语法一致,因为我没有使用它):

@Html.ActionLink("Print Results to Report", "DetailsReport", null, new {@id = "printreport")

$(function() {
   $('#printreport').click(function() {
      e.preventDefault();
      $(this).wrap('<form action="' + $(this).attr('href') + '?' + 
             $.param(@new JavaScriptSerializer().Serialize(Model)) + 
             '" style="display: inline" method="GET" />');
      $(this).parent('form').submit();
   });
});
相关问题