加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

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

发布时间:2020-12-15 20:55:21 所属栏目:asp.Net 来源:网络整理
导读:我有一个ASP.NET MVC 4应用程序.我的应用程序中有一个剃刀视图,它使用List类型作为模型. @model ListMeetingLog.Models.UserModel@{ Layout = null;}... 我正在迭代模型变量,如下所示: @foreach (var item in Model) { tr td @item.Name /td td @item.Surna
我有一个ASP.NET MVC 4应用程序.我的应用程序中有一个剃刀视图,它使用List类型作为模型.
@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",type = "participant"},null)
                        </td>
                    </tr>
                }

我需要将两个变量传递给具有操作链接的SavePerson操作.第一个是当前的UserModel,第二个是名为type的字符串变量.但在我的行动中,第一个参数是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 =#希望这有帮助,可以点击按钮或点击链接.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读