我怎么能传递一个texbox进入到PartialViewResult值? [英] How can I pass a value entered in a texbox to a PartialViewResult?
问题描述
我创建一个MVC应用程序,用户可以将项目添加到他们的购物车。他们还可以对某些项目的部分款项,所以我有一个TextBox为他们指定要付多少钱。我使用一个Ajax ActionLink的处理更新/添加到购物车的行为,这样我可以增加车数,而无需使用局部视图刷新屏幕。我的问题是,我无法找到一个方法来传递或访问该文本框进入到我的PartialViewResult函数的值。
I am creating an MVC app where the user can add items to their cart. They can also make partial payments on certain items so I have a TextBox for them to specify how much they want to pay. I am using an Ajax ActionLink to handle the Update/Add to cart actions so that I can increment the cart count without refreshing the screen using a partial view. My issue is that I can't find a way to pass in or access the value entered in the TextBox to my PartialViewResult function.
下面是我的模型......
Here is my Model...
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刷新购物车算...
Here are my initial load ActionResult and my AddAssignedFee PartialViewResult to refresh the cart count...
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
这是我的阿贾克斯行动环节,首先是添加没有指定金额的项目和它的作品。二是要更新的,可以有一个部分付款金额,我无法找到一个方法来量传递给PartialViewResult一个项目。
And here are my Ajax action links, the first is for Adding an item with no Amount specified and it works. The second is for Updating an item that can have an partial payment Amount and I can't find a way to pass the amount to the 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。
I have also tried ".SelectedAmount = Model.SelectedAmount" for the Update link but I can't seem to find a way to pass the entered Amount to the PartialViewResult.
有什么建议?
感谢您!
林赛罗
Thank you! Lindsay
推荐答案
你可以尝试做一个Ajax调用
you might try doing an ajax call
$('.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);
}
});
});
希望这有助于
这篇关于我怎么能传递一个texbox进入到PartialViewResult值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!