ASP.NET MVC - 故障传递模型在Html.ActionLink routeValues [英] ASP.NET MVC - Trouble passing model in Html.ActionLink routeValues

查看:121
本文介绍了ASP.NET MVC - 故障传递模型在Html.ActionLink routeValues的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的视图看起来是这样的:

My View looks like this:

<%@ Control Language="C#" 
    Inherits="System.Web.Mvc.ViewUserControl<TMS.MVC.BusinessSystemsSupport.Models.SearchDataTypeModel>" %>


<table class="classQueryResultsTable">
   <!-- the header -->
  <tr class="headerRow">

      <td>
      <%= Html.ActionLink("Effective Startdate",
                  "SortDetails",
                  "DataQryUpdate",
                  new
                  {
                      model = Model,
                      sortBy = "EffectiveStartDate",
                  },
                  new { @class = "classLinkLogDetails" })%>
      </td>

  </tr>


</table>

我的控制器动作:

My controller action:

    public ActionResult SortDetails(SearchDataTypeModel model, String sortBy)
    {

该模型参数为null。 SortBy参数填充。我可以在一个String属性传递从模型到没有问题的动作。我想在整个模型通不过。

The model parameter is null. The sortBy parameter is populated. I can pass in a String property from the model to the action with no problem. I want to pass in the entire model though.

任何想法我做错了吗?

推荐答案

另外一种选择是坚持你的TempData需要的数据。这将交给下一个请求,你可以在那里找回。您应该能够坚持整个模型对象,如果你想。

One other option is to persist the data you need in TempData. This will hand it to the next request, and you can retrieve it there. You should be able to persist the entire model object if you want to.

但它更容易(和更好的做法),只是再次从数据库中检索它,因为达林建议。

But it's easier (and better practice) to just retrieve it again from the database, as Darin suggests.

这篇关于ASP.NET MVC - 故障传递模型在Html.ActionLink routeValues的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆