How can I display a message on the master page. The message is sent by the action.
public ActionResult DisplayMessage()
{
ViewData["hello"] = "Hello!";
return View();
}
How can I display a message on the master page. The message is sent by the action.
public ActionResult DisplayMessage()
{
ViewData["hello"] = "Hello!";
return View();
}
In your view, do the following:
<%= html.encode(ViewData("Hello")) %>
If you want to place this data in another area outside of your view within your master page, you will need to define a new content placeholder.
Master Page:
<div id="somewhereOtherThanYourNormalViewArea">
<asp:ContentPlaceHolder ID="SecondaryContent" runat="server" />
</div>
View:
<asp:Content ID="Content2" ContentPlaceHolderID="SecondaryContent" runat="server">
<%= html.encode(ViewData("Hello")) %>
</asp:Content>
This is actually pretty simple. Just add the following in your controller:
ViewData["PassedToMaster"] = "From content page!";
Then in your MasterPage
you can just add the following code to look for it and if it is there do something with it:
<% if (ViewData["PassedToMaster"] != null)
{ %>
<%= ViewData["PassedToMaster"].ToString() %>
<% } %>