从MVC视图下载excel格式 [英] DOWNLOAD in excel format from MVC view

查看:72
本文介绍了从MVC视图下载excel格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为特定搜索类型(代理商名称Abc Enterprise)生成了一个视图,其中包含以下详细信息和一个webgrid(根据搜索)



I have a generated a view for a particular search type ( agency -name Abc Enterprise) having the following details and a webgrid(as per search)

Name of the Institute: ABC ENTERPRISE

Total No. of Feedback submitted: 5

Incountry Feedback: 5

Overseas Feedback: 0

Overall Score of the Institute: 3.3





现在我必须在excel中下载上面提到的详细信息以及该机构已执行的计划标题(标题详细信息已保存在表格中)



因此,如何在点击视图中下载此信息。



我尝试过:



搜索MVC控制器







Now i have to download in excel the above mentioned details along with the programme title the agency has conducted( title details has been saved in table)

So how to download this information in excel on click in view.

What I have tried:

MVC CONTROLLER FOR SEARCH


[Authorize]
       [HttpGet]
       public ActionResult TrainingInstitute(String agenda_no = "")
       {
           DisplayLndRep dn = new DisplayLndRep();
           DbAccess da = new DbAccess();
           LndFeedbackReport.Models.LoginViewModel uinfo = new LndFeedbackReport.Models.LoginViewModel();
           uinfo = da.FindUserInfoAD(User.Identity.Name);
           dn.FullName = uinfo.FullName;
           dn.FeedbackDetailList5=new List<lnd_prgm>();
           dn.Cre_name = agenda_no;
           dn.FeedbackDetailList5 = da.FindInstiStdCount(agenda_no);
           dn.app_count = dn.FeedbackDetailList5.Count;
           if(dn.app_count>0)
           {
            dn.ListArcGrid = new List<ReportLndFeedback>();
            dn.FeedbackDetailList4 = da.FindInstiPgmTypCount(agenda_no);
            dn.pg1_count = dn.FeedbackDetailList4.Count();
            dn.pg2_count = dn.app_count - dn.pg1_count;
            dn.score = da.FindTotalScore(agenda_no);
            dn.instiname = agenda_no.ToUpper();
            if(dn.score != null)
            {
                ViewBag.Total = (float)dn.score.Sum(x => x.pgm_avg);
            }
            dn.marks = ViewBag.Total/dn.score.Count();
                dn.PageSize = 10;

           }

           else
           {
               TempData["notice"] = "There is no such record for Training Institute." + agenda_no;
               return RedirectToAction("ReportModule", "Home");
           }

           return View(dn);
       }











查看代码








view Code

@model LndFeedbackReport.ViewModels.DisplayLndRep
@{
    ViewBag.Title = "Reports";
}
@*<br /><br />*@
@*<div class="pull-right">
        <a class="btn btn-info" href="@Url.Action("MainForm", "Home")">Back</a>  
        <a class="btn btn-info" href="@Url.Content("~/Account/LogOff/")">LogOff</a>
    </div>*@
@*<br /><br /><br />*@
<div class="row">
    <div class="panel panel-success" style="padding-top: 0px;">
        <div class="panel-heading">
            <span style="color:blue">Welcome</span>   <span style="color:black">User : </span><span style="color:red">@Model.FullName</span>      <span style="color:black">Salary Code : </span><span style="color:red">@Model.EmployeeId</span>      <span style="color:black">Designation : </span><span style="color:red">@Model.Designation</span>      <span style="color:black">Department : </span><span style="color:red"> @Model.DepartmentName </span>

        </div>
    </div>
</div>
<h3>Report Layout</h3>
<div class="row col-md-12">
    <div class="panel panel-body panel-danger">
        <br>Name of the Institute:<span style="color:blue;font-weight:bold"> @Model.instiname</span><br />
        <br>Total No. of Feedback submitted:<span style="color:blue;font-weight:bold"> @Model.app_count</span><br />
        <br>Incountry Feedback:<span style="color:blue;font-weight:bold"> @Model.pg1_count</span><br />
        <br>Overseas Feedback:<span style="color:blue;font-weight:bold"> @Model.pg2_count</span><br />
        <br>Overall Score of the Institute:<span style="color:blue;font-weight:bold"> @Model.marks</span><br />
        @*<br>Total No. of applications evaluated:<span style="color:blue;font-weight:bold"> @Model.evaluated_reports</span><br />
            <br>Total No. of applications not evaluated:<span style="color:blue;font-weight:bold"> @Model.not_evaluated_reports</span><br />*@
    </div>
</div>
<div class="wrap">
    <div class="content">
        @Html.AntiForgeryToken()
        <div class="inner-content" style="border:none">
            <span class="text-primary" style="color:crimson; font-size:larger">List of Feedback Submitted</span>
            <span>                                                                                                                                                                                                   <a class="btn btn-info" title="Report Module" href="@Url.Action("ReportModule", "Home")">Report Module</a></span>

        </div>
    </div>
</div>
<br />
@{
    WebGrid grid = new WebGrid(null, rowsPerPage: @Model.PageSize, canPage: true);
    grid.Bind(Model.FeedbackDetailList4, autoSortAndPage: true, rowCount: @Model.PageSize);
    grid.Pager(WebGridPagerModes.NextPrevious);
}
<div>
    @grid.GetHtml(tableStyle: "table table-bordered table-striped", headerStyle: "bg-success", selectedRowStyle: "bg-warning", footerStyle: "bg-warning",
    mode: WebGridPagerModes.All,
    firstText: "<< First",
    previousText: "< Prev",
    nextText: "Next >",
    lastText: "Last >>",
        columns: grid.Columns(
            //grid.Column("MIN_ID", "Id"),
            //grid.Column("MIN_DATE", "Date"),
       grid.Column("prgm_id", "Feedback ID", format: @<text><div style="text-align: center"><a title="View" href="@Url.Action("ShowProgramDetails", "Home", new { ac = item.prgm_id })">@item.prgm_id</a></div></text>),
                           grid.Column("prgm_type", "Feedback Type"),
                           grid.Column("Create_by", "Submitted By"),
                           grid.Column("from_date", "From Date", format: (item) => (item.from_date == null) ? "" : string.Format("{0:dd-MM-yyyy}", item.from_date)),
                           grid.Column("till_date", "Till Date", format: (item) => (item.till_date == null) ? "" : string.Format("{0:dd-MM-yyyy}", item.till_date)),
                           grid.Column("pgm_avg", "Score"),
                           grid.Column("fdk_remarks", "Remarks")
                           //grid.Column("agency_name", "Training Agency/Institute"),
                           //grid.Column("venue", "Venue      (City/State/Country)"),
                        @*grid.Column(header: "VIEW", format: @<text><a class="btn btn-default" title="View" href="@Url.Action("ShowProgramDetails", "Home", new { ac = item.prgm_id})"><img src="@Url.Content("~/Content/Images/View1.png")" width="20" height="20" alt="View" /></a></text>)*@

                ))
</div>
<div class="wrap">
    <div class="content">
        
        @Html.AntiForgeryToken()
        <div class="inner-content" style="border:none" align="left">
            @using (Ajax.BeginForm("DownloadTrainRep", "Home",new AjaxOptions { HttpMethod = "Post", UpdateTargetId = "result" }))
            {
                <span><button type="submit" class="btn btn-info">Download</button></span>
            }

        </div>
    </div>
</div>

推荐答案

以CSV格式下载,在Excel中打开:



ABC ENTERPRISE,5,5,0,3.3



等。
Download as CSV, open in Excel:

ABC ENTERPRISE, 5, 5, 0, 3.3

etc.


这篇关于从MVC视图下载excel格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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