将Store过程列放在Razor代码中 [英] Putting Store procedure columns in Razor code
本文介绍了将Store过程列放在Razor代码中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从MVC调用存储过程,它只返回单个记录。
SP包含:
i am calling store procedure from MVC, which returns single record only.
SP contains:
PROCEDURE [dbo].[GetMonthlyReport] @emplID INT = NULL,
@month VARCHAR(50) = NULL
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
END --If block ends
ELSE --Else block begins
BEGIN
RETURN 0
END --Else block ends
END
现在它正在从MonthlyRecord View中选择,empID,Overtime,Month,TotalDuration,
我想要做的是将这些字段放在自定义模板中,例如HTML TABLE或List,例如:
now it is selecting, empID, Overtime, Month, TotalDuration from MonthlyRecord View,
What i want to do is to put these fields in custom template e.g. HTML TABLE or List, like :
<table style="width:300px">
<tr>
<td>Employee ID</td>
<td>Month</td>
</tr>
<tr>
<td>@empID</td>
<td>@Month</td>
</tr>
</table>
somet hing dynamic。
MVC代码:
控制器:
something dynamic.
MVC Code:
Controller:
public ActionResult Generated_PaySlip(int? emplID, String month)
{
IEnumerable<GetMonthlyReportResult> PaySlip = DataContext.GetMonthlyReport(emplID, month).ToList();
return View(PaySlip);
}
查看:
@using EmployeeAttendance_app.Models
员工工资单
员工ID | 月 |
@empID | @Month |
View:
@using EmployeeAttendance_app.Models
Employee Pay Slip
Employee ID | Month |
@empID | @Month |
推荐答案
在视图中添加以下代码。
Add the following code in your view.
<table style="width:300px">
<tr>
<td>Employee ID</td>
<td>Month</td>
</tr>
@foreach(GetMonthlyReportResult emp in Mode)
{
<tr>
<td>@emp.empID</td>
<td>@emp.Month</td>
</tr>
}
这篇关于将Store过程列放在Razor代码中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文