2014-02-19 91 views
0

我正在使用存儲過程來訪問asp.net中的字段查看,我將db列放在HTML表中,它的工作狀態除了一個字段' NetSalary」。它不能被訪問,它說模型不包含它。我嘗試了很多方法,但無法工作。存儲無法從asp.net視圖中的存儲過程訪問的asp.net字段

ALTER PROCEDURE [dbo].[GetMonthlyReport] @emplID INT = NULL, 
    @month VARCHAR(50) = NULL, @BasicSalary int = null out ,@BSalaryHour int= Null out 
AS 
BEGIN 
    -- SET NOCOUNT ON added to prevent extra result sets from 
    -- interfering with SELECT statements. 
    SET NOCOUNT ON; 

    IF (@emplID IS NOT NULL AND @month IS NOT NULL) --If Block begins 
    BEGIN 
     SELECT * 
     FROM MonthlyRecord 
     WHERE Month = @month AND EmplID = @emplID 

     --------------------------------------------------------------- 
     Declare @StartDate Date, @EndDate Date, @mydate date, @TotalDays int, @TotalHours int 

     Set @mydate = GETUTCDATE() 
     Set @StartDate = (SELECT CONVERT(VARCHAR(25),DATEADD(dd,-(DAY(@mydate)-1),@mydate),101)) 
     Set @EndDate = (SELECT CONVERT(VARCHAR(25),DATEADD(dd,-(DAY(DATEADD(mm,1,@mydate))),DATEADD(mm,1,@mydate)),101)) 
     Set @TotalDays =((DATEDIFF(dd, @StartDate, @EndDate) + 1) 
      -(DATEDIFF(wk, @StartDate, @EndDate) * 1) 
      -(CASE WHEN DATENAME(dw, @StartDate) = 'Sunday' THEN 1 ELSE 0 END)) 
     Set @TotalHours = (@TotalDays * 8) 
     Set @BasicSalary = (Select BasicSalary from HrEmployee where [email protected]) 
     Set @BSalaryHour = @BasicSalary/@TotalHours 
     Select @BasicSalary as NetSalary, @BSalaryHour as SalaryPerHour 
     --------------------------------------------------------------- 

     Declare @No_Rows int 
     Select No_Rows= count(*) FROM MonthlyRecord 
     WHERE Month = @month AND EmplID = @emplID 
     Return @No_Rows 
    END --If block ends 
    ELSE --Else block begins 
    BEGIN 
     RETURN 0 
    END --Else block ends 
END 

控制器:

public ActionResult Generated_PaySlip(int? emplID, String month) 
{ 
    if (!String.IsNullOrEmpty(Session["Admin"] as string)) 
    { 
     int? basicSalary= 0; 
     int? BSalaryPerHour = 0; 
     IEnumerable<getmonthlyreportresult> PaySlip = DataContext.GetMonthlyReport(emplID, month, ref basicSalary, ref BSalaryPerHour).ToList(); 
     ViewBag.Month = Request.QueryString["Month"]; 
     //String NetSalary = DataContext.GetMonthlyReport(emplID, month).First() 
     ViewBag.Salary = basicSalary; 
     return View(PaySlip); 
    } 
    else 
    { 
     return RedirectToAction("IsAuth_Page", "Home"); 
    } 

查看:

@using EmployeeAttendance_app.Models 
@model IEnumerable<getmonthlyreportresult> 

@{ 

    var Item = Model.FirstOrDefault(); 
} 

<td> 
    Name 
</td> 
<td> 
    @Item.EmplName 
</td> 
<td> 
    Designation 
</td> 
<td> 
    @Item.DeptName 
</td> 

<tr style="border-removedsolid 3px black"> 
    <td>Total Working Time</td> 
    <td>@Item.OverallTime</td> 
    <td>Net Salary PKR</td> 
    <td>@Item.NetSalary</td> 
</tr> 
<table><tbody><tr> 
+0

你能告訴我們對正在執行sproc的數據庫的調用以及你如何設置它嗎? – Gjohn

+0

它已經提供,控制器代碼爲 – PreciseTech

+0

?對此有何幫助? – PreciseTech

回答