Click here to Skip to main content
15,916,702 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

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



My action on button submittion

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

     }
 }
Posted

1 solution

If you're using modern browsers (particularly IE10 or higher), you could use the formtarget attribute[^] on your button:
HTML
<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:
HTML
<noscript>
<a href="@Url.Action("Login", "Account")" target="_parent">Continue...</a>
</noscript>
<script>
parent.location.assign('@Url.Action("Login", "Account")');
</script>
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900