Reputation: 13
I have an Iframe in a view that i need to populate the src from my controller This is the part of the controller that it has to be called from.
else
{
//TODO: add after mobile detection is added back in
//if (Request.Browser.IsMobileDevice)
// return RedirectToAction("Index", "Mobile", new { Area = "" });
//else
return RedirectToAction("Index", "Home", new { Area = "" });
}
I know this is how youwould do it if it wasnt in MVC so how could i call my iframe from the controller?
ifr1.Attributes["src"] = "http://localhost:8000/index.php/login/?u=" + Session["username_s"] + "&p=" + Session["password_s"];
enter code here
Upvotes: 0
Views: 9581
Reputation: 6839
You should use ViewBag
in the target action, passing the URL, for exemple:
1) Your target redirect action should look like:
public ActionResult Index()
{
//Other code from the action here
ViewBag.IFrameSrc = "http://localhost:8000/index.php/login/?u=" + Session["username_s"] + "&p=" + Session["password_s"];
return View();
}
2) The Index
View should look like:
<iframe src="@ViewBag.IFrameSrc">
</iframe>
Upvotes: 1
Reputation: 1426
You can use ViewData
or ViewBag
for this purpose.
In your controller you should have the following:
else
{
//TODO: add after mobile detection is added back in
//if (Request.Browser.IsMobileDevice)
// return RedirectToAction("Index", "Mobile", new { Area = "" });
//else
ViewBag.IframeUrl = "http://localhost:8000/index.php/login/?u=" + Session["username_s"] + "&p=" + Session["password_s"];
return RedirectToAction("Index", "Home", new { Area = "" });
}
In you View you can use the following:
<iframe src="@(ViewBag.IframeUrl)"></iframe>
You can also use ViewData
by replacing ViewBag.IframeUrl
with ViewData["IframeUrl"]
Upvotes: 2