在下面我試圖在類級別上定義一個名爲_p的私有變量。用於索引的HTTP.POST將帶來一個用戶提供的值,我將使用該私有變量。在名爲ListOfVehicles的第二個方法中,我將訪問此變量。無法從同一類的不同方法/函數訪問類級別的私有變量
現在一切從理論上講都是好的,但是當我嘗試訪問這個私有變量時,我什麼也沒有得到,這是什麼都沒有發現。
Public Class QuotationController
Inherits System.Web.Mvc.Controller
'Private Variables
Dim _p As String
'Get Basic pickup and dropoff details
Function Index() As ActionResult
Return View()
End Function
'Function to get basic details out of the view
'and to redirect to ListOfVehicles
<HttpPost()>
Function Index(ByVal P As String, ByVal D As String) As ActionResult
_p = P
Return RedirectToAction("ListOfVehicles")
End Function
'Show list of vehicels
Function ListofVehicles() As ActionResult
ViewData("UserChoice") = "Pickup: " & _p
vehicleList = QB.GetQuotation(_p, _d)
Return View(vehicleList)
End Function
End Class
如果有兩個用戶呢? – SLaks