0

我正在创建一个 MVC 应用程序,用户可以在其中将项目添加到他们的购物车。他们还可以对某些项目进行部分付款,因此我有一个文本框供他们指定他们想要支付的金额。我正在使用 Ajax ActionLink 来处理更新/添加到购物车操作,这样我就可以在不使用局部视图刷新屏幕的情况下增加购物车计数。我的问题是我找不到将 TextBox 中输入的值传递或访问到我的 PartialViewResult 函数的方法。

这是我的模型...

Public Class StudentSchoolFee_Transaction

    Public Property SchoolFeeId As Integer
    Public Property Title As String
    Public Property Price As Decimal
    Public Property AmountDue As Decimal
    <DisplayFormat(ApplyFormatInEditMode:=True, DataFormatString:="{0:C2}")>
    Public Property Amount As Decimal
    Public Property Description As String
    Public Property AcceptPartialPayment As Boolean
    Public Property StudentId As Integer

    Public Property TransactionId As Integer

End Class

Public Class AssignedFeesModel

    Public Property StudentId As Integer
    Public Property StudentNumber As Long
    Public Property SiteId As String

    Public Property SelectedSchoolFeeId As Integer
    Public Property SelectedAcceptPartial As Boolean
    Public Property SelectedAmountDue As Decimal
    Public Property SelectedAmount As Decimal
    Public Property SelectedTransactionId As Integer

    Public Property AssignedFeesCol As System.Collections.Generic.List(Of   StudentSchoolFee_Transaction)

    Public Sub New()

    End Sub

    Public Sub New(ByVal _Deliver As EMS.Grid.Deliver, ByVal _StudentId As String)

        Dim SelectedStudent As New Library.Student(_Deliver, _StudentId)

        AssignedFeesCol = New System.Collections.Generic.List(Of StudentSchoolFee_Transaction)

        StudentId = SelectedStudent.Id
        StudentNumber = SelectedStudent.StudentNumber
        SiteId = SelectedStudent.SiteId

        'Load AssignedFeesCol   
    End Sub
End Class

这是我的初始加载 ActionResult 和我的 AddAssignedFee PartialViewResult 以刷新购物车计数...

    Function AssignedFees(ByVal StudentId As String, Optional ByVal ErrorMessage As String = "") As ActionResult
        Dim oDeliver As New EMS.Grid.Deliver
        oDeliver.UDLNameOrConnString = ConfigurationManager.ConnectionStrings("DefaultConnection").ConnectionString

        Dim m As New AssignedFeesModel(oDeliver, StudentId)

        Dim stu As New Library.MealHistoryDB.Student(oDeliver, m.StudentNumber, UserSession.GetSession.DistrictId)

        Return View(m)
    End Function

    Public Function AddAssignedFee(ByVal StudentId As Integer, ByVal SchoolFeeId As Integer, ByVal SelectedAmount As Decimal) As PartialViewResult

        Dim oDeliver As New EMS.Grid.Deliver
        oDeliver.UDLNameOrConnString = ConfigurationManager.ConnectionStrings("DefaultConnection").ConnectionString

        With New Library.Ecommerce.SchoolFee(oDeliver, SchoolFeeId)
            .AddToCart(oDeliver, UserSession.GetSession.ParentId, StudentId, SelectedAmount)
        End With

        Return PartialView("_CartButton") ', New Global.MSM.mobile.CartButton())

    End Function

这是我的 Ajax 操作链接,第一个是添加未指定金额的项目,它可以工作。第二个是更新一个可以有部分支付金额的项目,我找不到将金额传递给 PartialViewResult 的方法。

@Ajax.ActionLink("Add", "AddAssignedFee", "Parent", New With {.StudentId = currentItem.StudentId, .SchoolFeeId = currentItem.SchoolFeeId, .SelectedAmount = currentItem.Amount}, New AjaxOptions() With {.HttpMethod = "POST", .InsertionMode = InsertionMode.Replace, .UpdateTargetId = "btnCartContainer"}, New With {.class = "button"})


@Ajax.ActionLink("Update", "AddAssignedFee", "Parent", New With {.StudentId = currentItem.StudentId, .SchoolFeeId = currentItem.SchoolFeeId, .SelectedAmount = currentItem.Amount}, New AjaxOptions() With {.HttpMethod = "POST", .InsertionMode = InsertionMode.Replace, .UpdateTargetId = "btnCartContainer"}, New With {.class = "button"})

我还为更新链接尝试了“.SelectedAmount = Model.SelectedAmount”,但我似乎找不到将输入的金额传递给 PartialViewResult 的方法。

有什么建议么?

谢谢!林赛

4

1 回答 1

0

你可以尝试做一个ajax调用

$('.Link').on('click', function(){
    $.ajax({
        url: "@(Url.Action("AddAssignedFee", "Controller")",
        type: "POST",
        data: { textValue: $('.PaymentAmount').val(), data2: 'data2' }
        cache: false,
        async: true,
        success: function (result) {
            $(".Content").html(result);
        }
    });
});

希望这会有所帮助

于 2013-10-15T15:44:28.983 回答