ASP.NET MVC 4 通过 ActionLink 传递对象变量 [英] ASP.NET MVC 4 Passing Object Variable Through ActionLink

查看:22
本文介绍了ASP.NET MVC 4 通过 ActionLink 传递对象变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 ASP.NET MVC 4 应用程序.我的应用程序中有一个 razor 视图,可以将 List 类型用作模型.

I have an ASP.NET MVC 4 application. There is a razor view in my application that works with List type as a model.

@model List<MeetingLog.Models.UserModel>

@{
    Layout = null;
}
.
.
.

我像这样遍历模型变量:

I am iterating through Model variable like this:

@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>
                }

我需要通过操作链接将两个变量传递给 SavePerson 操作.第一个是当前的 UserModel,第二个是名为 type 的字符串变量.但是在我的操作中,第一个参数为空.但是字符串参数是正确的.我怎样才能做到这一点?

I need to pass two variables to SavePerson action with action links. First one is current UserModel, and second one is string variable named type. But in my action first parameter comes through as null. But string parameter comes correctly. How can I achieve this?

推荐答案

我为此使用 ajax 调用

I use ajax calls for this

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

如果你想使用 href = # 希望这会有所帮助,可以通过单击按钮或单击链接来调用.

and put the call in a button click or a link click if you want with href = # hopefully this helps.

这篇关于ASP.NET MVC 4 通过 ActionLink 传递对象变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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