如何将视图从iframe重定向到另一个视图 [英] How to Redirect the view from iframe to another view

查看:75
本文介绍了如何将视图从iframe重定向到另一个视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的asp.net mvc项目有问题。我有一个视图,在iframe视图中包含一个iframe按钮。在该提交按钮上,我想从当前视图重定向到另一个视图。得到它的新视图但是问题是视图在iframe内部。如何从iframe中逃脱?



我的iframe





< iframe width =900height =450frameborder =0src =@ Url.Action( QuestionView,Home)sandbox ='allow-forms allow-scripts allow-top'target =_ parent>< / iframe>







我的iframe视图包含beginform内的按钮



 <   div     class   =  button-next >  
< 输入 class = starrtexam type = submit value = 结束考试 name = 提交 / >
< / div >







我对按钮提交的操作



  public  ActionResult AnswerSubmit( string  s ubmit)
{
if (submit == 结束考试
{
return RedirectToRoute( new
{
controller = 帐户
action = 登录
});

}
}

解决方案

如果您使用的是现代浏览器(特别是IE10或更高版本) ),您可以使用 formtarget 属性 [ ^ ]:

< pre lang =HTML> < 输入 class = starrtexam < span class =code-attribute> type = submit value = 结束考试 名称 = submit formtarget = < span class =code-keyword> _ parent / >



否则,您需要返回一个使用Javascript更改父框架位置的视图:

 <   no   script  >  
< a href = @ Url.Action( Login, 帐户) target = _ parent > 继续... < / a < span class =code-keyword>>
< / no script >
< script >
parent。 location .assign(' @ Url.Action(Login,Account)' );
< / script >


hi
i have a problem in my asp.net mvc project . I have a view that contains a iframe at that iframe view contain a button. On that submit button i want to redirect from current view to another view . The new view is get it but the problem is that the view is inside the iframe .How can escape from iframe ?

My iframe


<iframe width="900" height="450" frameborder="0" src="@Url.Action("QuestionView", "Home")" sandbox='allow-forms allow-scripts allow-top' target="_parent"></iframe>




My iframe View contains button inside beginform

<div class="button-next">
     <input class="starrtexam" type="submit" value="End Exam" name="submit" />
 </div>




My action on button submittion

public ActionResult AnswerSubmit(string submit)
 {
     if (submit=="End Exam")
     {
         return RedirectToRoute(new
         {
             controller = "Account",
             action = "Login",
         });

     }
 }

解决方案

If you're using modern browsers (particularly IE10 or higher), you could use the formtarget attribute[^] on your button:

<input class="starrtexam" type="submit" value="End Exam" name="submit" formtarget="_parent" />


Otherwise, you'll need to return a view which uses Javascript to change the location of the parent frame:

<noscript>
<a href="@Url.Action("Login", "Account")" target="_parent">Continue...</a>
</noscript>
<script>
parent.location.assign('@Url.Action("Login", "Account")');
</script>


这篇关于如何将视图从iframe重定向到另一个视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆