1
我經歷了許多網站和建議,但無法使綁定概念正常工作。我面臨以下問題。將單選按鈕綁定到MVC中的對象3 VB.net
我有以下型號類,如下: 主視圖模型:
Public Class MasterVM
Public Property Language As LanguageVM
Public Property Question As QuestionVM
Public menus As List(Of MenuVM)
Public Property UserControlName As String
Public Property Model As Object
End Class
語言視圖模型
Public Class LanguageVM
#Region "Properties"
Public Property IsEnglish As Boolean
#End Region
End Class
我的控制器類:
Public Class WizardController
Inherits System.Web.Mvc.Controller
'
' GET: /Wizard
Function Index() As ActionResult
Dim oWizard As New Wizard
Dim oMasterWizard As New MasterVM
Dim IsNewlyIniated As Boolean = False
If (System.Web.HttpContext.Current.Session(Constants.WizardObjectCollection) IsNot Nothing) Then
If (System.Web.HttpContext.Current.Session(Constants.WizardObjectCollection).ToString <> "") Then
oMasterWizard = DirectCast(System.Web.HttpContext.Current.Session(Constants.WizardObjectCollection), MasterVM)
Else
IsNewlyIniated = True
End If
Else
IsNewlyIniated = True
End If
If (IsNewlyIniated) Then
oMasterWizard = oWizard.GetWizardInfo()
If (Session("Language").ToString() = "Spanish") Then
oMasterWizard.Wizard.Language.IsEnglish = False
Else
oMasterWizard.Wizard.Language.IsEnglish = True
End If
System.Web.HttpContext.Current.Session(Constants.WizardObjectCollection) = oMasterWizard
End If
Return View("Wizard", oMasterWizard)
End Function
<HttpPost()>
Function GetLanguageInfo(ByVal oLanguage As LanguageVM) As ActionResult
Try
Dim a As Integer
a = 10
Catch ex As Exception
Throw ex
End Try
End Function
End Class
我想在我的視圖中顯示兩個單選按鈕,顯示語言爲英語和西班牙語。默認情況下,它應該綁定到我的語言課isenglish和isspanish屬性。
當發生帖子時,如果用戶在選定屬性中更改了它,我應該得到該值。我怎麼能得到它。
我的ASCX頁的代碼如下:
<%@ Control Language="VB" Inherits="System.Web.Mvc.ViewUserControl(Of SBE.Services.MasterWizard.LanguageVM)" %>
<form method="post" action="/Wizard/GetLanguageInfo">
<fieldset>
<legend>Wizard Language</legend>
<p>Please select the language for your Wizard</p>
<%= Html.RadioButtonFor(Function(model) model.IsEnglish, True)%>English
<%= Html.RadioButtonFor(Function(model) model.IsEnglish, False)%> Spanish
<input id="btnNext" type="submit" value="Next">
一個更客觀的是,一旦我已經綁定的,我想通過用戶在對象選擇更新的價值,並通過它來發布在控制器中定義的動作。任何幫助將不勝感激。
我試圖上面的代碼和在視圖源I可以看到以下代碼:<輸入的ID =「IsEnglish」名稱=「IsEnglish」類型=「無線電」的值=「真」 />英文西班牙文。但由於某種原因,我的帖子操作不會在下一個按鈕點擊時激怒,以便知道該值是否被綁定。任何建議 - – 2012-03-27 19:50:17
謝謝芬克爾斯坦它的工作。我在帖子中更新了上述解決方案。 – 2012-03-27 20:01:12