0

I have a partial view with some text that can be modified using the ViewBag

@(ViewBag.FooText ?? "foo")

I populate ViewBag.FooText in the parent view from a resource file:

@
{
    ViewBag.FooText = MyResources.Common.FooText
}

My question is whether this is the best place to populate this property (and all other text resources) or would the related controller, or somewhere else, be more appropriate?

Breandán
  • 1,775
  • 21
  • 33

2 Answers2

1

I would suggest not using ViewBag if you can help it. It is better to use a strongly-typed viewmodel object, bind the resources to that object (in the controller or in the object itself), and then push the viewmodel to the partial view.

Davin Tryon
  • 64,963
  • 15
  • 144
  • 131
1

ViewBag isn't the best place to "populate" any property or data.

It will be much better if you store it in the Model. Model View Controller...

Read this answer of @Darin Dimitrov, an MVC master over here...

Community
  • 1
  • 1
gdoron is supporting Monica
  • 142,542
  • 55
  • 282
  • 355