Reputation: 3229
I have one Child action that call it from it's own controller & return Views/Shared/PartialViewName belong to my child action. again repeat this in another controller and it do the same. every thing is ok. but i reapet child action in some controllers DRY
How share one child action among controllers is it possible like shared partial views in views folder?
I utulize below but doesn't work:
@Html.Action("actionName","ControllerName")
update: I don't use Areas
here's my code:
public class ItemCatController : Controller
{
[ChildActionOnly]
public ActionResult PopulateTree() { return View("Tree", GetTree()); ... lots of other code }
}
return view:
<h2>ItemCat Index</h2>
<hr />
<button onclick="New()">new</button>
<br />
@Html.Action("PopulateTree")
and this:
public class ItemController : Controller
{
*// repeat these codes again, this is aginst DRY principle.*
[ChildActionOnly]
public ActionResult PopulateTree() { return View("Tree", GetTree()); ... lots of other code }
}
return this :
<h2>Index Item</h2>
<hr />
@Html.Action("PopulateTree")
<br />
Upvotes: 0
Views: 257