Click here to Skip to main content
15,886,678 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi i am getting this error A data source must be bound before this operation can be performed,i am getting error on view i.e grid part

this is model code

C#
using FT.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using System.Web.Mvc;

namespace FT.Models
{
    public class ReportGenerationModel
    {

        List<VmsTypeDetailModel> getreportcategorylist;
        List<AppointmentModel> serachedAppointmentModelList;
        //List<DptWise> DptWiseReport { get; set; }
        public ReportGenerationModel()
        {
            getreportcategorylist = new List<VmsTypeDetailModel>();
            serachedAppointmentModelList = new List<AppointmentModel>();


        }

        //Common Fields
        public int Id { get; set; }
        public string EmployeeId { get; set; }
        public string UserName { get; set; }
        public string TypeMasterName { get; set; }
        public Nullable<System.DateTime> RecurringToDateTime { get; set; }
        public Nullable<System.DateTime> RecurringFromDateTime { get; set; }



        //DPTWise
        public string VisitingDepartmentName { get; set; }
        public string ReasonForVisit { get; set; }
        public string ContactPersonName { get; set; }
        public Nullable<System.TimeSpan> VisitorCheckInTime { get; set; }
        public Nullable<System.TimeSpan> VisitorCheckOutTime { get; set; }
        public string CompanyName { get; set; }


        // public List<VmsTypeDetailModel> ReportcategoryList { get; set; }
        public List<VmsTypeDetailModel> ReportcategoryList
        {
            get
            {
                return getreportcategorylist;
            }
            set
            {
                getreportcategorylist = value;
            }
        }

        public List<AppointmentModel> SerachedAppointmentModelList
        {
            get
            {
                return serachedAppointmentModelList;
            }
            set
            {
                serachedAppointmentModelList = value;
            }
        }

        public AppointmentModel Appointment { get; set; }

        public VisitorModel Visitor { get; set; }
        public List<DptWise> DptWiseReport { get; set; }
    }

    public class DptWise
    {

        public string VisitingDepartmentName { get; set; }
        public string ReasonForVisit { get; set; }
        public string ContactPersonName { get; set; }
        public Nullable<System.TimeSpan> VisitorCheckInTime { get; set; }
        public Nullable<System.TimeSpan> VisitorCheckOutTime { get; set; }
        public string CompanyName { get; set; }

    }
}
</pre>

this is controller code

   public ActionResult VMSReports()//sowji
        {

            ReportGenerationModel reportGenerationModel = new ReportGenerationModel();
            //reportGenerationModel = this._iEmailConfigurationService.GetReportList();
            reportGenerationModel = this._iEmailConfigurationService.GetReportList();

            return View(reportGenerationModel);
        }
        [HttpPost]
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult VMSReports(ReportGenerationModel GetreportGenerationModel)
        {
            GetreportGenerationModel.ReportcategoryList = this._iEmailConfigurationService.GetReportList().ReportcategoryList;
            if (GetreportGenerationModel.TypeMasterName == "101")
            {
                List<ReportGenerationModel> reportGenerationModel = this._iEmailConfigurationService.GetReportDetails(GetreportGenerationModel);
                List<DptWise> lstDptwise = new List<DptWise>();
               foreach (ReportGenerationModel item in reportGenerationModel)
                 // foreach(DptWise item in lstDptwise )
                {
                    lstDptwise.Add(new DptWise { CompanyName = item.CompanyName, ContactPersonName = item.ContactPersonName, ReasonForVisit = item.ReasonForVisit, VisitingDepartmentName = item.VisitingDepartmentName, VisitorCheckInTime = item.VisitorCheckInTime, VisitorCheckOutTime = item.VisitorCheckOutTime });
                }
                GetreportGenerationModel.DptWiseReport = lstDptwise;
            }
            return View(GetreportGenerationModel);

        }


view code

HTML
@using GridMvc.Html
@{
    ViewBag.Title = &quot;VMSReports&quot;;
    Layout = &quot;~/Views/Shared/_LayoutAdmin.cshtml&quot;;

   // var grid = new WebGrid(Model.SerachedAppointmentModelList, defaultSort: &quot;Id&quot;, rowsPerPage: 9);
    var grid = new WebGrid(Model.DptWiseReport, defaultSort: &quot;VisitingDepartmentName&quot;, rowsPerPage: 9);

   // var grid = new WebGrid(Model, rowsPerPage: 9);
}
</pre>
 <div id="gridContent" style="padding: 20px;">
                @grid.GetHtml(
            tableStyle: "gridTable",
            headerStyle: "gridHead",
            footerStyle: "gridFooter",
            rowStyle: "gridRow",
            alternatingRowStyle: "gridAltRow",
            columns:
            grid.Columns(
             grid.Column("DepartmentName", @Resources.Appointment.VisitingDepartmentName, format: @<text>  <span class="display-mode">@item.VisitingDepartmentName</span></text>, style: "col1Width"),
             grid.Column("To", @Resources.Appointment.RecurringToDateTime, format: @<text>  <span class="display-mode">@Model.RecurringToDateTime</span> </text>, style: "col2Width"),
             grid.Column("From", @Resources.Appointment.RecurringFromDateTime, format: @<text>  <span class="display-mode">@Model.RecurringFromDateTime</span></text>, style: "col1Width"),
             grid.Column("Company Address", @Resources.Appointment.CompanyName, format: @<text>  <span class="display-mode">@item.CompanyName</span> </text>, style: "col2Width"),
             grid.Column("ContactPersonName", @Resources.Appointment.ContactPersonName, format: @<text> <span class="display-mode">@item.ContactPersonName</span></text>, style: "col3Width"),
             grid.Column("ReasonForVisit", @Resources.Appointment.ReasonForVisit, format: @<text> <span class="display-mode">@item.ReasonForVisit</span></text>, style: "col3Width"),
              grid.Column("Intime", @Resources.Appointment.VisitorCheckInTime, format: @<text> <span class="display-mode">@item.VisitorCheckInTime</span></text>, style: "col3Width")
             //grid.Column("Export to excel", format: @<text>&lt;button type="submit" class="btn btn-primary pull-right btn-sm RbtnMargin" onclick="location.href='@Url.Action("ViewAppointment", "Appointment", new { aId = Model.AppointmentID })'">@Resources.Appointment.View&lt;/button></text>)
           ))

            </div>
Posted
Updated 30-Aug-15 4:01am
v3
Comments
Sergey Alexandrovich Kryukov 28-Aug-15 11:42am    
In what line?
Anyway, bind the data source.
—SA

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