I want to show the content of ViewData, which holds string in my case, on a modal window. For this, I am using following code in my view.
<h2><%= Html.Encode(ViewData["Message"]) %></h2>
<p>
To learn more about ASP.NET MVC visit <a href="http://asp.net/mvc" title="ASP.NET MVC Website">http://asp.net/mvc</a>.
</p>
<form runat = "server">
<div onload = "poponload('<%=ViewData["sample"].ToString()%>')">
<input type="submit" value="show" id="submitBtn"/>
</div>
<script type="text/javascript" language="Javascript">
function poponload(msg) {
alert(msg.toString().length);
if (msg.toString().length > 0) {
my_window = window.open("",
"mywindow1", "status=1,width=350,height=150");
my_window.document.write(msg.toString());
}
}
</script>
</form>
The controller contains simple action methods as follows.
public ActionResult Index()
{
ViewData["Message"] = "Welcome to ASP.NET MVC!";
return View();
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Index(FormCollection collection)
{
ViewData["Message"] = "Welcome to ASP.NET MVC!";
ViewData["sample"] = "My name is kaps";
return View();
}
I want to show the contents of ViewData["sample"] using Window.open(). But this code is unable to show me the desired output. Can anyone please tell me how can I achieve it?
Thanks.