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" })

2013/10/02

[C#] Customize the delimiter of CSV when loading it by using Excel.Workbook.Open() (VBA)

I got an old program which can load a csv file and do something. The customer wants to change the delimiter from comma (,) to others like ";", "|", or "-"... etc. Sounds like an easy job. But no, it's not. The approach that uses on opening the csv file is
using Microsoft.Office;
....
xlsApp = new Excel.ApplicationClass();
xlsWBs = xlsApp.Workbooks;
xlsWB = xlsWBs.Open(TempFileName,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing);