Asp.net mvc 来自控制器的Iframe Src
我在视图中有一个Iframe,我需要从我的控制器填充src,这是必须从中调用它的控制器的一部分Asp.net mvc 来自控制器的Iframe Src,asp.net-mvc,iframe,Asp.net Mvc,Iframe,我在视图中有一个Iframe,我需要从我的控制器填充src,这是必须从中调用它的控制器的一部分 else { //TODO: add after mobile detection is added back in //if (Request.Browser.IsMobileDevice) // return RedirectToAction("Index", "Mobi
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 = "" });
}
我知道如果它不在MVC中,你会这样做,那么我如何从控制器调用我的iframe呢
ifr1.Attributes["src"] = "http://localhost:8000/index.php/login/?u=" + Session["username_s"] + "&p=" + Session["password_s"];
enter code here
为此,您可以使用
ViewData
或ViewBag
在控制器中,您应该具有以下功能:
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 = "" });
}
<iframe src="@(ViewBag.IframeUrl)"></iframe>
在您的视图中,您可以使用以下各项:
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 = "" });
}
<iframe src="@(ViewBag.IframeUrl)"></iframe>
您还可以使用
ViewData
将ViewBag.IframeUrl
替换为ViewData[“IframeUrl”]
来使用ViewData
或ViewBag
在控制器中,您应该具有以下功能:
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 = "" });
}
<iframe src="@(ViewBag.IframeUrl)"></iframe>
在您的视图中,您可以使用以下各项:
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 = "" });
}
<iframe src="@(ViewBag.IframeUrl)"></iframe>
您还可以使用
ViewData
将ViewBag.IframeUrl
替换为ViewData[“IframeUrl”]
来使用ViewData
或ViewBag
在控制器中,您应该具有以下功能:
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 = "" });
}
<iframe src="@(ViewBag.IframeUrl)"></iframe>
在您的视图中,您可以使用以下各项:
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 = "" });
}
<iframe src="@(ViewBag.IframeUrl)"></iframe>
您还可以使用
ViewData
将ViewBag.IframeUrl
替换为ViewData[“IframeUrl”]
来使用ViewData
或ViewBag
在控制器中,您应该具有以下功能:
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 = "" });
}
<iframe src="@(ViewBag.IframeUrl)"></iframe>
在您的视图中,您可以使用以下各项:
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 = "" });
}
<iframe src="@(ViewBag.IframeUrl)"></iframe>
您还可以通过将
ViewBag.IframeUrl
替换为ViewData[“IframeUrl”]
来使用ViewData
,您应该在目标操作中使用ViewBag
,传递URL,例如:
1) 您的目标重定向操作应如下所示:
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();
}
<iframe src="@ViewBag.IFrameSrc">
</iframe>
2) 索引
视图应如下所示:
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();
}
<iframe src="@ViewBag.IFrameSrc">
</iframe>
您应该在目标操作中使用
ViewBag
,传递URL,例如:
1) 您的目标重定向操作应如下所示:
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();
}
<iframe src="@ViewBag.IFrameSrc">
</iframe>
2) 索引
视图应如下所示:
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();
}
<iframe src="@ViewBag.IFrameSrc">
</iframe>
您应该在目标操作中使用
ViewBag
,传递URL,例如:
1) 您的目标重定向操作应如下所示:
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();
}
<iframe src="@ViewBag.IFrameSrc">
</iframe>
2) 索引
视图应如下所示:
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();
}
<iframe src="@ViewBag.IFrameSrc">
</iframe>
您应该在目标操作中使用
ViewBag
,传递URL,例如:
1) 您的目标重定向操作应如下所示:
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();
}
<iframe src="@ViewBag.IFrameSrc">
</iframe>
2) 索引
视图应如下所示:
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();
}
<iframe src="@ViewBag.IFrameSrc">
</iframe>