Asp.net mvc 4 ASP.NET MVC 4通过ActionLink传递对象变量

Asp.net mvc 4 ASP.NET MVC 4通过ActionLink传递对象变量,asp.net-mvc-4,razor,html.actionlink,Asp.net Mvc 4,Razor,Html.actionlink,我有一个ASP.NETMVC4应用程序。在我的应用程序中有一个razor视图,它使用列表类型作为模型 @model List<MeetingLog.Models.UserModel> @{ Layout = null; } . . . @型号列表 @{ 布局=空; } . . . 我正在迭代模型变量,如下所示: @foreach (var item in Model) { <tr>

我有一个ASP.NETMVC4应用程序。在我的应用程序中有一个razor视图,它使用列表类型作为模型

@model List<MeetingLog.Models.UserModel>

@{
    Layout = null;
}
.
.
.
@型号列表
@{
布局=空;
}
.
.
.
我正在迭代模型变量,如下所示:

@foreach (var item in Model)
                {
                    <tr>
                        <td>
                            @item.Name
                        </td>
                        <td>
                            @item.Surname
                        </td>
                        <td>
                            @Html.ActionLink("Click", "SavePerson", "Meeting", new {model = item, type = "coordinator"}, null)
                            @Html.ActionLink("Click", "SavePerson", "Meeting", new {model = item, type = "participant"}, null)
                        </td>
                    </tr>
                }
@foreach(模型中的变量项)
{
@项目名称
@项目.姓氏
@ActionLink(“单击”、“保存人”、“会议”,新建{model=item,type=“coordinator”},null)
@ActionLink(“单击”、“保存人”、“会议”,新建{model=item,type=“participant”},null)
}

我需要将两个变量传递给带有操作链接的SavePerson操作。第一个是当前用户模型,第二个是名为type的字符串变量。但在我的操作中,第一个参数是null。但是字符串参数是正确的。我怎样才能做到这一点

不能通过querystring传递复杂类型的实例。这是使用它的方法:

@Html.ActionLink("Click", "SavePerson", "Meeting", new {x = item.x, y = item.y, ..., type = "participant"}, null)

为此,我使用ajax调用

$('.btnSave').on('click', function(){
    $.ajax({
        url: '@(Url.Action("SavePerson", "Meeting"))',
        type: 'post',
        data: {
            Value1: 'Value1',
            Value2: 'Value2'
        },
        success: function (result) {
            alert('Save Successful');
        }
    });
});

如果你想使用href=#的话,可以点击按钮或链接来调用。希望这会有所帮助。

当你编码传递的值(新的{})时,你实际上可以,这有点奇怪 您需要做的是将其作为您正在构建的新对象传递,以使其最终成为:

@Html.ActionLink("Link Name", "LinkActionTarget", new Object{model = item, type ='Coordinator'}

其中Object是对象的名称,model和type是该对象的属性

,但这是有效的:@Html.ActionLink(“单击”,“保存人”,“会议”,项,空)。此格式项正确,但无法传递第二个参数。