我正在創建一個MVC應用程序,用戶可以在其中添加項目到他們的購物車。他們也可以在某些項目上進行部分支付,所以我有一個TextBox讓他們指定他們想要支付多少。我正在使用Ajax ActionLink處理更新/添加到購物車操作,以便我可以增加購物車數量而無需使用局部視圖刷新屏幕。我的問題是,我無法找到一種方法將文本框中輸入的值傳遞給我的PartialViewResult函數。如何將在texbox中輸入的值傳遞給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。
有什麼建議嗎?
謝謝! 林賽