如何将按钮的url动作传递给sub而不是控制器中的函数?

时间:2017-02-23 03:07:54

标签: asp.net-mvc vb.net

我正在做一个Web API项目,我应该将值从视图页面传递到控制器中的sub来验证值。

<button type="button" class="btn btn-default btn-sm" onclick="location.href='@Url.Action("SaveConsultationFee", New With {.strPVID = Model.LoadPatientBiodata.pvid, .strBillNo = Model.LoadPatientBiodata.pbid, .strRefID = ViewBag.strRefID, .dblAmount = ViewBag.dblTotal, .strRemarks = ViewBag.strCategory})'">Save</button>

我将子名称放在按钮的url.action中。我知道url动作应该与函数一起使用,但是如何将值传递给sub呢?因为我想到的是,sub将执行相关函数来验证每个值。如果函数返回false值,则sub将退出,以便每次检查其他值时页面都不会重新加载。

Private Sub SaveConsultationFee(ByVal strPVID As String, ByVal strBillNo As String, ByVal strRefID As String, ByVal dblAmount As Double, ByVal strRemarks As String) 
    If CheckPatientPaymentStatus(strPVID) = False Then
        MsgBox("Patient's bill is settled", vbInformation)
        Exit Sub
    End If

    '//Check compulsary fields
    '//Check consultation charges
    '//Get cosultant invoice ID

    If strRefID Is Nothing Then
        '// Create New
    Else
        Dim strErr = UpdateCharges(strPVID, strRefID, dblAmount, strRemarks)
    End If

    '//Save diagnosis
    '//Update charges
    '//Update log charges act
End Sub

Private Function CheckPatientPaymentStatus(ByVal strPVID As String) As Boolean
    If strPVID IsNot Nothing Then
        Dim Query As String = " SELECT * FROM patientvisit
                                WHERE pvid = '" & strPVID & "'
                                AND paymentstatus <> 'Paid' AND (BillClosed <> 1 OR BillClosed Is Null) "

        Dim Results = dbb.Database.SqlQuery(Of patientvisit)(Query)

        If Results.Count > 0 Then
            CheckPatientPaymentStatus = True
        Else
            CheckPatientPaymentStatus = False
        End If
    Else
        CheckPatientPaymentStatus = True
    End If

    Return CheckPatientPaymentStatus
End Function


Private Function UpdateCharges(ByVal strPVID As String, ByVal strRefID As String, ByVal dblAmount As Double, ByVal strRemarks As String) As String
    On Error GoTo err
    Dim Query = " UPDATE patientbill 
                  SET amount = " & dblAmount & ", remarks = '" & strRemarks & "', UpdOn = GETDATE() 
                  WHERE pvid = '" & strPVID & "' AND refid = '" & strRefID & "' "

    dbb.Database.ExecuteSqlCommand(Query)

err:
    Dim strErr = "Ref '" & Err.Number & "': " & Err.Source & vbCrLf & vbCrLf & Err.Description

    Return strErr
End Function

我尝试了上面的代码,但错误显示如下:

The resource cannot be found

我还是MVC的新手。有人可以帮我吗?

0 个答案:

没有答案