开发者

ASP.NET MVC Data passing

I need a good example 开发者_运维百科or guideline which could give me a pattern for data passing between view and partial view.

For example I have a view which contains several partial views. I refresh these partial view by ajax. So I need to pass data among view and its partial views.

The best way would be if I could pass data without using Temp data dictionary.

Anybody know a good article about this?

l.


1) One way would be to call RenderAction() and as such go to controller action and then controller would return the data to the View or PartialView as a Model for it. In general, you should be using strongly typed views and partial views wherever possible and try to avoid using ViewData and TempData.

2) You can also use RenderPartial("some view", ObjectData) to send an entire business object or POCO object or CLR variable to the partial view.

3) You can also have partial views strongly typed the same as your main view (the one that would then load up those partials). If you have the same type then doing just RenderPartial("some view") would render your partial view with the same Model that the "main" or "parent" view has.

I don't think I have more than 3-5 usages of ViewData or TempData in my apps, I almost never use it.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜