views:

88

answers:

4

Hi all;

alt text

http://a.imageshack.us/img709/5208/errorss.jpg

pls help, how to make ?

+1  A: 

The error is caused by the fact the ViewData["mydata"] is null, so calling ToString() fails.

Ben Robinson
ViewData["mydata"] is not null , ViewData["mydata"] = "BlaBlaa"
Oraclee
It would appear from the code that they are setting ViewData["mydata"] in the Action before returning the view, from that I believe they know what's causing the error but don't understand why it's null in the first place.
Lazarus
+2  A: 

You are setting the viewData in an action within your controller, but calling render partial to display the partial view. The render partial never calls the action being used to generate the html, it is just passing the .ascx file into the browswer request. You either a) need to use html.renderaction or b) pass the viewdata in your renderpartial call.

A) <% Html.RenderAction("leftside", new { controller = "UserControls" }); %>

B)<% Html.RenderPartial("~/Views/Shared/UserControls/leftside.ascx", null, ViewData);%>

updated to C# (not sure on the part B, anyone check to make sure this is how not to send a model in c#)?

EDIT 2 - Part B will not work unless you set the ViewData in your parent controller/action calling the primary page. The only way to access the ViewData that you set in your leftside action is to call the RenderAction method in part A.

Tommy
@Tommy, Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately., your code is not work pls help
Oraclee
This code will not worked directly copied from my answer as you are using c# and this is in vb
Tommy
Updated to c# for you
Tommy
Thank you Tommy, i trying
Oraclee
A: 

You can use Html.RenderAction or Html.RenderPartial in such scenarios

1) <% Html.RenderAction("leftside","UserControls");%> Or

2)<% Html.RenderPartial("leftside");%>

When Html.RenderPartial() is called with just the name of the partial view, ASP.NET MVC will pass to the partial view the same Model and ViewData dictionary objects used by the calling view template.

Please let me know if this works!

Shruthi
Yeah, the issue is he is not setting that ViewData in the parent controller/action but in his partial view action which he is never calling when he uses the RenderPartial method.
Tommy
A: 

The problem is that your ViewData is in SiteMaster and from there u are rendering partial, so the partial does not see ViewData on the SiteMaster.

You need to pass the view data to the RenderPartial method so that Viewdata will be passed on to the partial view.

You can do so like this

<% Html.RenderPartial("partialViewName",ViewData) %>
Nikola Markezic