0

I'm using RazorEngine to render and parse some cshtml programmatically (and get html). I need to pass programmatically some data (a list of object) to a template and use these objects inside this template.

How to pass these data and how to use them inside my template, and then parse it?

Thanks!

ff8mania
  • 1,553
  • 3
  • 19
  • 28
  • possible duplicates. http://stackoverflow.com/questions/5120317/dynamic-anonymous-type-in-razor-causes-runtimebinderexception – qamar May 09 '14 at 16:28
  • @Clamidity: the problem is that I have no idea. At the moment I'm doing so to parse the template: result = Razor.Parse(cshtmlTemplate, view); Where cshtmlTemplate is the template cshtml in which I wanto to pass my IMyObject list of object – ff8mania May 09 '14 at 16:42
  • Have you tried something like this: result = Razor.Parse(cshtmlTemplate, myObject); with the following at the top of the cshtmlTemplate: @model Namespace.For.IMyObject? – Shattuck May 09 '14 at 16:51
  • @Clamidity: and what about my view object that contains my data? I need a further object that is different from the view I'm already passing – ff8mania May 09 '14 at 16:57

1 Answers1

1

You have to cast the objects going into the template.

ViewData is used to pass data from controller to corresponding view.

ViewData vs ViewBag vs TempData vs Session

There is also a video tutorial.

Agent Shark
  • 517
  • 2
  • 6