0

From controller, I'm returning a value using ViewBag to razor page. Based on the value of ViewBag, I have displayed some partial views like this:

@if (ViewBag.CourseName == "Physics")
{
    <partial name="_ExpPhysicsPartial"/>
}

@if (ViewBag.CourseName == "Chemistry")
{
    <partial name="_ExpChemistryPartial"/>
}

Is this a kind of deprecated technique somehow in terms of security purpose?

Shunjid Rahman
  • 409
  • 5
  • 17
  • i always try and make the `View` as dumb as possible. Let the `Controller` build an appropriate model. – jazb Nov 26 '19 at 05:57

1 Answers1

1

Not deprecated as such, but also not preferred. Its always better to populate a data model and pass that to the view. There are a few advantages of that, one important one being catching compile time vs run time issues with a data model passed as opposed to ViewBag being directly used in a view since its dynamic. This post explains more. Hope that helps.