tags:

views:

511

answers:

1

I have followed the blog post written by Steve Sanderson at blog.codeville.net/2008/10/14/partial-requests-in-aspnet-mvc. It all work fine when follow it exactly but I was hoping that someone may have looked at it and be able to assist me in adapting it slightly.

I basically have this "partial request" calling from one controller to another and this works fine. I then want to foreach through the data and create a drop down list. The problem is that I need to convert it to an IEnumerable to do this but it fails telling me that I cannot convert a void to an IEnumerable.

The lkine fails on is in the view and is:

foreach (var category in (IEnumerable<MyObject>) ((PartialRequest)ViewData["ReturnedData"]).Invoke(ViewContext))

Clearly, knowing how to answer this is hard without seeing the code. This is all in the aforementioned post but as it is reasonably lengthy I do not want to post it all in here. I understand that this makes answering this difficult and am hoping that someone has ready that post and can assist.

Thanks in advance.

+3  A: 

The PartialRequest Invoke method doesn't return anything, it writes the HTML that the request generates to the response. The idea is that you can invoke a controller action that renders an MVC View User Control rather than a View. You can make a partial request to this controller action and have it render the control directly into the response stream rather than using the Html.RenderPartial. Since the control writes directly to the response, you don't have a chance to interact with it's output.

tvanfosson