Showing posts with label MVC. Show all posts
Showing posts with label MVC. Show all posts

2018/05/08

Redirect the parent window when inside a frame

One of my project it's website has a frameset setting like the following:
<frameset border="0" frameborder="NO" framespacing="0" rows="110,*">
<frame index="" name="topFrame" noresize="" ome="" scrolling="NO" src="@Url.Action("AgentHeader", "Home")"><frame>
<frame name="main"></frame>
</frameset>

The "main" frame is the major workplace. However, if I set the logout method like the following, only the "main" frame will by redirected to login page. The "topFrame" is still there.
public ActionResult Logout()
{
    .....

    return RedirectToAction("Login", "Home");
}

How to redirect includes the whole page? (The parent window actually)
Here is what I got from the stack overflow and it works for me:
public ActionResult Logout()
{
    .....

    return Content("<html><script>window.top.location.href = 'your url';</script></html>");
}

Please share some other approaches with me if they work in this kind of situation.


Reference: Redirect the entire page from MVC3 Razor iFrame page to a different URL

2015/08/11

Add Tooltip to Html helpers

Use the "title" attribute to the html helper. For example:
@Html.CheckBoxFor(m => m.ForTest, new { title = "測試" })

2015/08/10

Apply Enum onto @Html.DropDownListFor

enum GenderType
{
    male,
    femail,
    others
}
@Html.DropDownListFor(model => model.Gender, new SelectList(Enum.GetValues(typeof(GenderType))))

@Html.LabelFor /wo newline

Here is how to prevent @Html.LabelFor from rendering a new line:
@Html.LabelFor(m => m.Title, new { style = "display:inline" })