0

我在 sql server 2008 r2 中有以下存储过程

ALTER PROCEDURE [dbo].[cusGenDenialReport](@StartDate VARCHAR(11), @EndDate VARCHAR(11))
AS

BEGIN
SELECT     VisitTransactions.PatientVisitid AS PatientVisitid,   VisitTransactions.PaymentMethodId AS PaymentMethodId, 
                  VisitTransactions.Adjustments AS Adjustments, VisitTransactions.Transfers AS Transfers, Transactions.[Action] AS [action], Transactions.Type AS type, 
                  Transactions.Name AS name, Transactions.Amount AS Amount, VisitTransactions.Payments, PatientVisit.TicketNumber, TransactionDistributions.Code, 
                  InsuranceCarriers.Name AS InsName,  PatientVisitProcs.CPTCode AS CPT, PatientVisit.Visit AS DateOfVisit, VisitTransactions.LastModified AS DateOfEntry, Transactions.Note, 
                  PatientVisitProcsAgg.InsBalance AS InsBalance, PatientVisitProcsAgg.PatBalance AS PatBalance, Transactions.LastModified, 
                  Transactions.ActionTypeMId, MedLists.FunctionName, MedLists.Description AS PaymentType, 
                  DoctorFacility.ListName AS Doctor
FROM         VisitTransactions INNER JOIN
                  Transactions ON VisitTransactions.VisitTransactionsId = Transactions.VisitTransactionsId INNER JOIN
                  TransactionDistributions ON Transactions.TransactionsId = TransactionDistributions.TransactionsId INNER JOIN
                  PatientVisit ON VisitTransactions.PatientVisitid = PatientVisit.PatientVisitId INNER JOIN
                  InsuranceCarriers ON VisitTransactions.InsuranceCarriersId = InsuranceCarriers.InsuranceCarriersId INNER JOIN
                  PatientVisitAgg ON PatientVisit.PatientVisitId = PatientVisitAgg.PatientVisitId INNER JOIN
                  PatientVisitProcsAgg ON TransactionDistributions.PatientVisitProcsId = PatientVisitProcsAgg.PatientVisitProcsId INNER JOIN
                  MedLists ON Transactions.ActionTypeMId = MedLists.MedListsId INNER JOIN
                  PatientVisitProcs ON PatientVisitProcsAgg.PatientVisitProcsId = PatientVisitProcs.PatientVisitProcsId INNER JOIN
                  DoctorFacility ON PatientVisit.DoctorId = DoctorFacility.DoctorFacilityId
WHERE     (VisitTransactions.Payments = 0) AND VisitTransactions.LastModified BETWEEN @StartDate and @EndDate


END

我从前面的存储过程的结果集中创建了一个数据模型并将其命名为 demo10DenialReport.edmx。

我需要做的是让最终用户将开始日期和结束日期输入到两个不同的文本框中。然后我希望视图显示过滤后的结果。

我的观点是这样的:

@model IEnumerable<OEWebPortalMVCVer5.Models.cusGenDenialReport1_Result>

@{
ViewBag.Title = "Denial";
}

<h2>Denial</h2>

<p>
@Html.ActionLink("Create New", "Create")

@using (Html.BeginForm("startDate", "endDate", FormMethod.Get))
{
    <p> Start Date: @Html.TextBox("startDate") <br />
        End Date: @Html.TextBox("endDate") <br />
        <input type="submit" value="Filter" />
    </p>
    }
</p>
<table>
<tr>
    <th>
        @Html.DisplayNameFor(model => model.PatientVisitid)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.PaymentMethodId)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.Adjustments)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.Transfers)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.action)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.type)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.name)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.Amount)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.Payments)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.TicketNumber)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.Code)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.InsName)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.CPT)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.DateOfVisit)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.DateOfEntry)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.Note)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.InsBalance)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.PatBalance)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.LastModified)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.ActionTypeMId)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.FunctionName)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.PaymentType)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.Doctor)
    </th>
    <th></th>
</tr>



@foreach (var item in Model) {
<tr>
    <td>
        @Html.DisplayFor(modelItem => item.PatientVisitid)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.PaymentMethodId)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.Adjustments)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.Transfers)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.action)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.type)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.name)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.Amount)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.Payments)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.TicketNumber)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.Code)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.InsName)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.CPT)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.DateOfVisit)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.DateOfEntry)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.Note)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.InsBalance)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.PatBalance)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.LastModified)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.ActionTypeMId)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.FunctionName)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.PaymentType)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.Doctor)
    </td>
    <td>
        @Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) |
        @Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) |
        @Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ })
    </td>
</tr>
}

</table>

我不担心底部的编辑、详细信息或删除链接(我知道这些是不正确的。

这是我的部分控制器:

        public ActionResult Denial(String startDate, String endDate)
    {

        if (!String.IsNullOrEmpty(startDate))
        {
            return View();
        }

        if (!String.IsNullOrEmpty(endDate))
        {
            return View();
        }

        return View();
    }

当我编译和运行代码时它抛出的错误是这样的

NullReferenceException was unhandled by user code

它在这条线上抛出

@foreach (var item in Model) {

我想如果我能停止那个错误,我将能够显示视图。让我知道我是否错了

谢谢

4

1 回答 1

0

如果您只想在模型为空时进行空检查以忽略 foreach 错误。

@if( Model != null ) {
  foreach (var item in Model) {
   ...
  }
}
于 2013-06-05T22:12:26.573 回答