0

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

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

pls help, how to make ?

4 Answers 4

3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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
This code will not worked directly copied from my answer as you are using c# and this is in vb
1

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

2 Comments

ViewData["mydata"] is not null , ViewData["mydata"] = "BlaBlaa"
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.
0

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!

1 Comment

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

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) %>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.