0

Which is the best way to pass a DatatTable from one view to another in MVC3 Razor?

Nithesh Narayanan
  • 11,481
  • 34
  • 98
  • 138
  • What do you mean on pass some data from one view to another? Can you add some code samples how your views and actions looks like and what you are trying to achieve? – nemesv Aug 17 '12 at 06:55
  • i just want to redirect to another view from my current view.. also want to pass a some data in tabular form .. – Nithesh Narayanan Aug 17 '12 at 07:03

3 Answers3

3

Persist it in your backend and then simply pass the id around and have the controller action retrieve the DataTable from wherever you persisted it.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
1

Whatever data you require should be in a ViewModel. Pass the ViewModel from the controller to the View. If you require a separate but related View consider using

Html.RenderPartial("PartialViewName", Model.YourDataTable)

If the second view has nothing to do with the first view, don't pass it around, simply call

@Html.RenderAction 
from within your first view to load your second view to the response stream.

If you are looking at persisting this across requests this depends if you have persisted it in your database or not. Either day, consider using caching to keep it around for a few seconds (or longer) see the "in memory cache" class in this post

How to cache data in a MVC application

Community
  • 1
  • 1
Adam Tuliper
  • 29,982
  • 4
  • 53
  • 71
0

I am agree with Sir Darin Dimitrov. But still you are insist with doing same than you can use TempData for it.

For more information follow this ViewBag, ViewData and TempData

Community
  • 1
  • 1
alok_dida
  • 1,723
  • 2
  • 17
  • 36