我想在我的項目中使用方法Html.Action()。 我有兩個項目。如何在使用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處理。
如果您不明白我的描述,請寫評論。 –