views:

43

answers:

2

Hi,

I was trying to use a shared partial view to render when a particular listing page has no data. I wanted to use ViewData to pass information from the page into my listing control, which would then conditionally render the NoData partial view using the ViewData values.

I would like to be able to specify them in the view markup, not in the controller action, but when I add them in the view the don't seem to inherit down into child partial views (like the Nodata partial view). However, specifying them in the ViewData values in the controller actions works fine, the data is available all the way down...

Does anyone know why it behaves this way?

+2  A: 

When rendering a partial you can also pass the ViewData.

<% Html.RenderPartial("NoData", ViewData); %>
David Liddle
A: 
<%Html.RenderPartial("partialViewName", "viewData", "model"); %>

it is a best practice to do the decision inside the controller, if you have a scenario to make a decision inside the view, separate them and call them inside the controller conditionally

Rony