从mvc3中的视图页面调用控制器功能 [英] Calling a controller function from view page in mvc3

查看:101
本文介绍了从mvc3中的视图页面调用控制器功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi


我想从视图页面调用一个函数。

hi
I want to call a function from view page.

@Html.Action("check", "EventController");



并检查执行该函数


and check execute that function

[ChildActionOnly]
      [ActionName("check")]
      public void checkevent()
      {
          int e=0;
         // return View(db.EventManagers.ToList());
      }



我遵循这种方法,但它给出了错误。



请告诉我我该怎么办?


I am following this approach, but its giving errors.

Please tell me how can I do it ?

推荐答案

使用Html.RenderAction和Html.Action.Both这些方法允许你从视图中调用一个动作方法并输出视图中的操作结果。两者之间的区别在于Html.RenderAction将结果直接呈现给Response(如果操作返回大量HTML,则效率更高)而Html.Action返回带有结果的字符串。请检查此链接更多想法

http://haacked.com/archive/ 2009/11/17 / aspnetmvc2-render-action.aspx [ ^ ]
Use Html.RenderAction and Html.Action.Both of these methods allow you to call into an action method from a view and output the results of the action in place within the view. The difference between the two is that Html.RenderAction will render the result directly to the Response (which is more efficient if the action returns a large amount of HTML) whereas Html.Action returns a string with the result.Please check this link you get more idea
http://haacked.com/archive/2009/11/17/aspnetmvc2-render-action.aspx[^]


这篇关于从mvc3中的视图页面调用控制器功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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