如何将在texbox中输入的值传递给PartialViewResult?

我正在创建一个MVC应用程序,用户可以在其中添加项目到他们的购物车。 他们还可以对某些商品进行部分付款,因此我有一个TextBox,用于指定他们想要支付的金额。 我正在使用Ajax ActionLink来处理Update / Add to cart操作,这样我就可以增加购物车数量,而无需使用局部视图刷新屏幕。 我的问题是我找不到传入或访问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  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"}) 

我也为Update链接尝试了“.SelectedAmount = Model.SelectedAmount”,但我似乎无法找到将输入的Amount传递给PartialViewResult的方法。

有什么建议?

谢谢! 林赛

你可能会尝试做一个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); } }); }); 

希望这会有所帮助