2011-09-03 66 views
0

我會盲目盯着這個。當我點擊保存視圖時,發送到控制器保存方法的模型沒有設置值,它們都是默認值。 我錯過了什麼?我實際上是從另一個項目中使用完全相同的技術... 數據在我的視圖中填充得很好,我可以編輯它並單擊保存,代碼在控制器中輸入SetSiteTerms方法,但沒有任何數據風景。 :-( 我知道這是一些簡單和愚蠢的,但我就是不能看到它返回控制器後的模型屬性未設置

型號:

Imports System.ComponentModel.DataAnnotations 
Imports System.Runtime.Serialization 

<KnownType(GetType(SiteToA))> _ 
Public Class SiteToA 

    <ScaffoldColumn(False)> _ 
    Public Property ID As Integer = 0 
    Public Property AgreementHTML As String = String.Empty 
    Public Property AgreementName As String = String.Empty 
    Public Property IsActive As Boolean = False 

    Public Sub New() 
     MyBase.New() 
    End Sub 
End Class 

查看:

<%@ Control Language="VB" Inherits="System.Web.Mvc.ViewUserControl(Of Community_Portal_Admin.SiteToA)" %> 
<% Using Html.BeginForm("SetSiteTerms", "SiteToA", FormMethod.Post, New With {.id = "SiteTermsForm"})%> 


    <div class="gridFrame"> 
     <% Html.Telerik().EditorFor(Function(m) m.AgreementHTML) _ 
        .Name("AgreementHTML") _ ' Name must be the same as the property name in the model 
        .Encode(True) _ 
        .HtmlAttributes(New With {.style = "height:300px;"}) _ 
        .Render()%> 
     <br /> 
     <div class="smallFrameLeft">   
      <%: Html.ActionLink("Cancel", "Index", "Home", Nothing, New With {.class = "t-button", .Style = "font-size:12px;"})%> 
     </div> 
     <div class="smallFrameRight"> 
      <input type="submit" value="Save" class="t-button" />  
     </div> 
    </div> 
<% End Using%> 

控制器:

Imports Telerik.Web.Mvc 

Public Class SiteToAController 
    Inherits System.Web.Mvc.Controller 

    Function Index() As ActionResult 
     Dim setting As SiteToA 
     Try 
      setting = SiteToARepository.One(Function(d) d.IsActive = True) 
      ViewData.Model = setting 
      Return PartialView() 
     Catch ex As Exception 
      Throw 
     End Try 
    End Function 

    <HttpPost()> _ 
    Function SetSiteTerms(ByVal model As SiteToA) As ActionResult 
     Dim setting As SiteToA 
     Try 
      setting = SiteToARepository.One(Function(d) d.ID = model.ID) 
      TryUpdateModel(setting) 
      If Not SiteToARepository.Update(setting) Then Throw New Exception("There was a problem during update") 
      Return PartialView() 
     Catch ex As Exception 
      Return PartialView() 
     Finally 
      If Not setting Is Nothing Then 
       setting.Dispose() 
       setting = Nothing 
      End If 
     End Try 
    End Function 
End Class 

編輯: 我更新了我的視圖和控制器。 del被填充,可以在視圖中進行編輯,但是當我使用保存按鈕發佈時,發送到控制器的模型沒有數據?

+0

有沒有幫助,可以針對這個有過嗎?這一定很簡單。把我的大腦裝在這裏.... –

回答

0

我已經更新了原單後顯示由Telerik的,所提供的答案也是我與模型的其餘問題是一個愚蠢的缺失:笑