ASP.NET MVC(4)通过对象变量通过的ActionLink [英] ASP.NET MVC 4 Passing Object Variable Through ActionLink

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

问题描述

我有一个ASP.NET MVC应用4。有一个在我的应用程序的剃刀观点,与列表类型作为一个样板工程。

  @model名单< MeetingLog.Models.UserModel>@ {
    布局= NULL;
}



我通过这样的模型变量迭代

  @foreach(以型号VAR项)
                {
                    &所述; TR>
                        &所述; TD>
                            @项目名
                        < / TD>
                        &所述; TD>
                            @ item.Surname
                        < / TD>
                        &所述; TD>
                            @ Html.ActionLink(点击,SavePerson,会议,新的{模式=项,TYPE =协调员},NULL)
                            @ Html.ActionLink(点击,SavePerson,会议,新的{模式=项,TYPE =参与者},NULL)
                        < / TD>
                    < / TR>
                }

我需要通过两个变量来SavePerson行动操作链接。第一个是当前的usermodel,而第二个是字符串变量命名类型。但是,在我的行动的第一个参数来通过为空。但字符串参数来正确。我怎样才能做到这一点?


解决方案

我用这个Ajax调用

  $('。btnSave')。在('点击',功能(){
    $阿贾克斯({
        网址:'@(Url.Action(SavePerson,会议)),
        类型:'后',
        数据:{
            值1:'值1',
            值2:'值'
        },
        成功:函数(结果){
            警报(保存成功);
        }
    });
});

和把该呼叫单击按钮或链接点击,如果你想与HREF =#希望这会有所帮助。

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

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?

解决方案

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');
        }
    });
});

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天全站免登陆