I need to be able to call @Html.Partial() without knowing at design time what the partial file will be. I'd like to do something like...

In the Controller:

string partial;
switch (some_val) {
    case 1:
        partial = "help.cshtml";
        break;

    case 2:
        partial = "legal.cshtml";
        break;

    // Other cases here...

    default:
        partial = "default.cshtml";
        break;
}

ViewBag.partial = partial;

And in the View:

@Render.Partial (@ViewBag.partial)

...or...

@Render.Partial ("@ViewBag.partial")

Note, there is no Model.

Is this possible?

Thanks, Jeff

Related posts

Recent Viewed