将数据传递到主页面和用户控件从按钮单击视图

时间:2012-02-23 09:01:58

标签: asp.net-mvc

我的情景是在MVC中

我的页面(视图)具有用户控件(部分视图)和母版页。我的页面中有按钮(查看)。点击按钮

1)我需要在用户控制中加载网格,
2)我必须在主页面中使用div来显示确认消息,例如“Successfull loaded”。

我在一些论坛中看到单独执行这两个动作,但我需要在单击按钮中触发这两个动作。

我该怎么做?

1 个答案:

答案 0 :(得分:0)

您可以使用javascript。

$("#button-id").live('click', function()
{

   $('#master-page-message-id').text('Your message');
   //Send request to server
   $.ajax({
      url: @Url.Action(...),
      error : function(...){
          $('#master-page-message-id').text('Your failure message');
      },

      success: function(data){ 
         $('#master-page-message-id').text('Your success message');
         //update your greed if you get json response
         greed.update(data);
         //OR if you get simple html response
         $("#greed-id").html(data);
      }
   });

});