May I ask why you were using this approach in the first place? I think you could achieve the same thing by making your View
strongly typed, and pass the message as the View
's Model
.
Inherits="System.Web.Mvc.View<Message>"
If you already have a strongly typed View
, you could make a custom class in your class library that has room for your message, for example
public class ModelWithMessage {
public Message Message { get; set; }
public Object Model { get; set; }
public ModelWithMessage(Message Message, Object Model) {
this.Message = Message;
this.Model = Model;
}
}
You can of course make that type generic as well, allowing for a ModelWithMessage<T>
construct and avoiding having to cast the Model
to whatever type you need.
Another way to do it would be to use TempData
. In your Controller, set
TempData["Message"] = "Hello world!";
Then in your View
you write the message out simply with
<%= TempData["Message"] %>
Which approach you choose depends on what your Message class contains.