What is ChildActionOnly?
Let we discuss with example, public class ChildActionTestingController : Controller Here GetUserDetails method is non-action method. Theย GetUserDetails method cant able to access by URL like ChildActionTesting/GetUserDetails. @Html.Action(“GetUserDetails”, “ChildActionTesting”) After declare GetUserDetails as childactiononly attribute, then it can’t allow to access through url. If you try to access, it show the error msg like below. It will treat as a normal method. “The action ‘GetUserDetails’ is accessible only by a child request.”Where to use ChildActionOnly?
Creating a Child Action Method
{
public ActionResult GetUserDetails(int userId)
{
//Your Logic Here !!!
return PartialView(“GetUserDetails”, null);
}
}
Leave A Comment