mvc webgrip ve excel export

      Yorum yok mvc webgrip ve excel export
[HttpPost]
public ActionResult Export(string module)
{
    SiteEntities db = new SiteEntities();

    WebGrid grid = null;
    if(module == "Tercümeler")
        grid = new WebGrid(db.Tercume,,columnNames:new []{"Id", "Kod", "Tr", "En"}, canPage: false, canSort: false);
    else if (module == "Listeler")
        grid = new WebGrid(db.Liste, canPage: false, canSort: false);
    else if (module == "Lokasyonlar")
        grid = new WebGrid(db.Lokasyon, canPage: false, canSort: false);

    Response.Clear();
    Response.ClearHeaders();
    Response.ClearContent();
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    Response.ContentEncoding = System.Text.Encoding.GetEncoding("windows-1254");
    Response.Charset = "windows-1254";

    Response.Buffer = true;
    Response.ContentType = "application/vnd.xls";
    string fileName = string.Format("{0}.xls", module);
    Response.AddHeader("content-disposition", string.Concat("attachment;filename=", fileName));
    string html = string.Format("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=windows-1254\" /></head><body>{0}</body></html>", grid.GetHtml());

    Response.Write(html);
    Response.End();

    return View();
}
<div class="panel panel-default">
    <div class="panel-heading">Export List</div>
    <div class="panel-body">
        <div class="row">
            @foreach (var module in Model)
            {
                <div class="col-md-4">
                    <form action="/Home/Export" method="post">
                        <input type="hidden" name="module" value="@module.Name" />
                        <button class="btn btn-primary" type="submit">
                            @module.Name <span class="badge">@module.Count</span>
                        </button>
                    </form>
                </div>
            }
        </div>
    </div>
</div>

 

Bir cevap yazın

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir