Can I use a hybrid approach that passes information in the ViewBag (C#) / ViewData (VB) but also includes a model
For example, I started passing a simple title through an error controller to an error view:
<!-- language: lang-vb -->Function NotFound() As ActionResult
Response.StatusCode = 404
ViewData.Add("Title", "404 Error")
Return View("Error")
End Function
This worked fine and the View had access to the property @ViewData("Title")
Then I wanted to include some of the exception information that is automatically routed by Custom Errors in the HandleErrorInfo
object like this:
Then, on the View, I declared a Model like this:
@ModelType System.Web.Mvc.HandleErrorInfo
Now I can access properties like @Model.Exception.Message
but my @ViewData("Title")
has disappeared.
The WebViewPage(Of TModel)
still has a ViewData
property, but it looks like I can't pass anything to it from the controller unless it's explicitly in the model.
Of course, as a workaround, I could create a base class that can strongly type storage for each object, but that seems a little heavy handed when all I want to pass in through the ViewBag is the title.
Is there a way to use both ViewBag AND the Model at the same time?