从调用视图控制器? [英] Calling controller from view?

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

问题描述


  • 控制器1 - 指数()>返回视图1

  • 控制器2 - 指数()>返回视图2

  • Controller3 - 指数()>返回VIEW3 ....

  • Controller1000 - 指数()>返回View1000

  • Controller1 - Index() > return View1
  • Controller2 - Index() > return View2
  • Controller3 - Index() > return View3 ....
  • Controller1000 - Index()> return View1000

ControllerAAAA - GiveMeSomething(....)>返回PartialView1

ControllerAAAA - GiveMeSomething(....) > return PartialView1

目标:
在视图1添加PartialView1的结果为1000。

Objective: Add the result of PartialView1 on the View 1 to 1000.

解决方案:
这些控制器1到1000可以从保存所需ControllerAAAA强类型对象的特殊类继承,然后我可以打电话,从认为,PartialView1并通过所需要的对象。
我认为这是做了正确的道路。

Solutions: The controllers 1 to 1000 could inherit from a special class that holds the strongly typed object needed for the ControllerAAAA and then I could call, from the view, the PartialView1 and pass the object needed. I think this is the correct way to do it.

其他选项:我也可以对视图一些Ajax调用控制器

Other option: I also could have some ajax on the view to call the controller.

然而我想知道如果我可以简单的调用从视图1控制器AAAA查看1000和避免继承的类?
是这样的:

However I would like to know if I could simple call the Controller AAAA from the View1 to View 1000 and avoid the inherited class? Something like:

<%= CallController(GiveMeSomething,ControllerAAAA,新的参数(值:东西,值2:11)%>

这可能吗?怎么样?

推荐答案

您可以使用

<% Html.RenderAction<MyController>(m => m.LatestNews()); %>

我认为你需要的MVC期货这个......你可以从这里下载:
MVC期货

但是使用这个时候你要小心为不符合MVC模式,你的观点应该是愚蠢的,只是显示被传递给它的数据。虽然可以方便的做这样的事情的导航菜单的。

But you should be careful when using this as its does not conform to the MVC pattern, your views should be dumb and just display data that is handed to it. Although it can be handy for doing things like navigation menu's.

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

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