【发布时间】:2015-10-05 16:30:49
【问题描述】:
我想在我的项目中使用方法 Html.Action()。 我有两个项目。
- 项目 1 - 区域 - HomeController - IndexAction
-
项目 2 - 我编写了一个函数助手以在我的布局中使用。
public static IHtmlString RenderTest(this HtmlHelper htmlHelper) { string mhs = ""; mhs += htmlHelper.Action("Index", "Home", new { area = "area" }); return new MvcHtmlString(mhs); }
对于项目1,我写了一个路线图:
context.MapRoute("area_default",
"Theme/{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional },
namespaces: new[] { string.Format("{0}.Controllers", this.GetType().Namespace) }
);
如何使用此函数加载另一个程序集中的控制器?
Html.Action("Index","Home", new { area = "area" });
此外,我在每个程序集中都有一个重复的控制器名称,
例如Namespace1.FooController 和 Namespace2.FooController
我的路线没有问题。此外,我可以通过 URL/路由调用不同程序集中的任何控制器。
但我不能在我的HtmlHelper.Action() 中使用这些网址。
实际上,我想在另一个程序集中的控制器中调用一个动作,并将该动作的视图作为 HtmlString 但已处理。
【问题讨论】:
-
如果你不明白我的描述,请写评论。
标签: c# asp.net-mvc