Thursday, December 20, 2012

@Html.ActionLink to call action in different controller

@Html.ActionLink has many overloads (at least 17), and so sometimes it becomes confusing if the operation is not so straight-foward. 

For example, if you want to execute an Action of different controller, you must take care to use it like following:

@Html.ActionLink("Link Text", "MyAction", "MyController", new {id = item.ID}, null)
 

Its important to pass the last parameter (which is, "hostname"),
eventhough if you pass it as "null". Doing this will take up proper overload and will call the action from different controller.


1 comment:

  1. Awesome blog. I enjoyed reading your articles. This is truly a great read for me. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work.

    ReplyDelete

Thanks for visiting my blog.
However, if this helped you in any way, please take a moment to write a comment.

Thanks
Nirman