0

Though i invoke action method from actionlink present in the view.Its giving me error "action 'Demo' is accessible only by a child request".

Akash
  • 71
  • 5
  • please add relevant code for the above problem – Rajshekar Reddy May 17 '16 at 07:28
  • If you have a method with `[ChildActionOnly]` then it can only be called by `@Html.RenderAction()` (the whole purpose of `[ChildActionOnly]` is to prevent it be called via a link) –  May 17 '16 at 07:29
  • You can either use `@Html.Action` or `@Html.RenderAction` as @Stephen Muecke suggested – Bon Macalindong May 17 '16 at 07:34
  • //Action and Controllerpublic class DemoController : Controller { // GET: Demo public ActionResult MyView() { return View(new string[]{"Apple,Mango,Strawberry"}); } [ChildActionOnly] public ActionResult Demo() { return PartialView("Demo"); } } – Akash May 17 '16 at 07:34
  • //View @section Body {
    This is body section

    @Html.ActionLink("Demo","Demo","Demo") }
    – Akash May 17 '16 at 07:36

0 Answers0