返回到post控制器时未设置模型属性



看这个我都快瞎了。当我点击视图上的save时,被发送到控制器的save方法的模型没有设置值,它们都是默认值。我错过了什么?实际上,我正在使用另一个项目中完全相同的技术……数据在我的视图中填充得很好,我可以编辑它并单击保存,代码在控制器中输入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

编辑:我更新了视图和控制器。任何想法为什么我的模型被填充,可以在视图中编辑,但当我发布保存按钮,模型发送到控制器没有数据??

我已经更新了原始帖子,以显示Telerik提供的答案,同时我对模型其余部分的问题是一个愚蠢的缺失:lol

最新更新