I have called a view from another with Html.Action
method. I want to call the same action with a parameter Inside the child view, when user click the action link.
When I write this code I get this error message:
Html.ActionLink("link", "Configure", new { id = 2 })
The action 'Configure' is accessible only by a child request.
How can i handle this issue?
Edit: I'll try to reexplain the issue:
my parent view is ConfigureMethod.cshtml. I call child child view like that:
@Html.Action("Configure", "Payment");
It goes to this controller and returns actionresult(not partialview) inside ConfigureMethod view:
[ChildActionOnly]
public ActionResult Configure()
{
}
inside configure view i make an action link like that:
Html.ActionLink("link", "Configure", new { id = x.Id })
It should goes to this controller:
[ChildActionOnly]
public ActionResult Configure(int Id)
{
}
However when childonly attribute is written it gives error. When I remove this attribute it works but results comes directly, not inside ConfigureMethod view.
thanks.
There are two things I would like to point out,
Child actions are only meant to be rendered as PartialView. So decorating with [ChildActionOnly]
attribute means, this is the action must return PartialViewResult
.
When we are calling ActionLink(), it will generate a link to a View not Partial View. Even if you will not decorate with [ChildActionOnly]
, then a link to a partial view makes no sense.
So, first decide if you want a View or Partial View and then design accordingly.