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

前端之家收集整理的这篇文章主要介绍了asp.net-mvc-4 – ASP.NET MVC 4通过ActionLink传递对象变量前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个ASP.NET MVC 4应用程序.我的应用程序中有一个剃刀视图,它使用List类型作为模型.
  1. @model List<MeetingLog.Models.UserModel>
  2.  
  3. @{
  4. Layout = null;
  5. }
  6. .
  7. .
  8. .

我正在迭代模型变量,如下所示:

  1. @foreach (var item in Model)
  2. {
  3. <tr>
  4. <td>
  5. @item.Name
  6. </td>
  7. <td>
  8. @item.Surname
  9. </td>
  10. <td>
  11. @Html.ActionLink("Click","SavePerson","Meeting",new {model = item,type = "coordinator"},null)
  12. @Html.ActionLink("Click",type = "participant"},null)
  13. </td>
  14. </tr>
  15. }

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

解决方法

我使用ajax调用
  1. $('.btnSave').on('click',function(){
  2. $.ajax({
  3. url: '@(Url.Action("SavePerson","Meeting"))',type: 'post',data: {
  4. Value1: 'Value1',Value2: 'Value2'
  5. },success: function (result) {
  6. alert('Save Successful');
  7. }
  8. });
  9. });

如果你想用href =#希望这有帮助,可以点击按钮或点击链接.

猜你在找的asp.Net相关文章