3

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.

mavera
  • 3,171
  • 7
  • 45
  • 58

1 Answers1

8

There are two things I would like to point out,

  1. Child actions are only meant to be rendered as PartialView. So decorating with [ChildActionOnly] attribute means, this is the action must return PartialViewResult.

  2. 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.

Richard Ev
  • 52,939
  • 59
  • 191
  • 278
Manas
  • 2,534
  • 20
  • 21
  • I edited question to clearify issue with regard to your post. – mavera Jan 15 '12 at 12:14
  • @mavera, As you have mentioned Html.ActionLink(....) will generate a link like , on click on the link it will redirect to another page, So the action should not have [ChildAction] attribute. Where as Html.Action(...) will return a view/partial view with in the context of parent view. [ChildAction] means the action can not be triggered directly but with in a parent context. – Manas Jan 15 '12 at 16:28