开发者

Need To Access ViewData on MasterPage... or other options

I am using MVC2 in VS2010 with .Net 4.0. I have a situation in which I will have a bunch of partial views that I need to all have the same template. Basically I need them all wrapped with the same DIV (and ot开发者_JAVA百科her junk). I just want one place to change this DIV... so I used a master page. It works great, all the partial views use that master, and if I need to change something its no problem.

Problem space: I need to have some of the View specific data, in this case its the Id of the record the view displays, shown in the Id id the DIV. Now I realize I could just create another placeholder, but I need this id to be in 10 places, not 1.

<div id="<%: ViewObjectId %>">
  <asp:contentplaceholder id="ViewStuff" runat="server"/>
</div>

I have tried to add the Id to the ViewData, however it seems in MVC2 the ViewData is missing in action.

I could create a parent Action that calls a child view, but the problem with that is it takes away from the flexibility of having any parameters I want... all views would have to use the same signature.

Any thoughts or suggestions?


Not sure what you mean by "however it seems in MVC2 the ViewData is missing in action." ViewData is there and should work for what you want. You'll have to access it as ViewData["ViewObjectId"] if you want it, though.

If this doesn't work, could you post code samples to show how you are trying to set the ViewData value?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜