Asp.net mvc 4 我可以从视图向控制器发送完整对象(@item)吗?

Asp.net mvc 4 我可以从视图向控制器发送完整对象(@item)吗?,asp.net-mvc-4,razor,Asp.net Mvc 4,Razor,我用Actionlink制作了一张表格。Actionlink打开新视图,作为我要发送@item-full对象的操作参数。我怎样才能做到 型号: public class MyClass { //I have properties here. } 控制器: public class MyController : Controller { public ActionResult ActionName(MyClass tm) {

我用Actionlink制作了一张表格。Actionlink打开新视图,作为我要发送@item-full对象的操作参数。我怎样才能做到

型号:

public class MyClass
    {
        //I have properties here.
    }
控制器:

public class MyController : Controller
{
    public ActionResult ActionName(MyClass tm)
        {
            //have a breakpoint here
            return View();
        }
}
视图:


专栏标题一
专栏标题二
专栏标题三
@foreach(@Model中的var项)
{
@项目1.PropertyOne
@项目2.propertytw
@item.PropertyTree
@如果(ViewData[“smth”]=“true”)
{
@ActionLink(“编辑”、“ActionName”、“我的”、新的{tm=@item},null)
}
}
我需要说的是,一切正常,只有在点击ActionLink之后,在MyClass tm中保存为“null”。不是@item。如果我不想写“param1=@item.propertyOne,param2=@item.propertyTwo”等,我如何将其发送到操作


谢谢。

使用超链接(ActionLink)是不可能的。任何作为附加路由值放置的内容(区域除外)都将大部分转换为querystring键值对。不过你有很多选择

由于项是模型的一部分,因此在操作方法中构造,因此您可以:

  • 缓存操作方法中的项目列表(可能是通过,也可能是类似的),以便在另一个操作方法中使用

  • 存储会话中的项目列表

  • 使用相同的检索方法(即相同的服务调用)获取 另一个操作方法中的相同项


好了,我受够了。非常感谢。
<table>
    <tr>
        <th> Column title one </th>
        <th> Column title two </th>
        <th> Column title three </th>
    </tr>

@foreach (var item in @Model)
    {
        <tr>
            <td> @item.PropertyOne </td>
            <td> @item.PropertyTwo </td>
            <td> @item.PropertyThree </td>

            @if (ViewData["smth"] == "true")
                {
                    <td> @Html.ActionLink("Edit", "ActionName", "My", new { tm = @item }, null) </td>
                }
        </tr>  
    }
</table>