这是一个MVC3,VB.NET应用程序,使用剃刀视图引擎。出于某种原因,我的模型没有被传递回控制器。在我查看变量时的post动作中,它在集合中有0个项目。关于为什么这可能是???
的任何想法Post Controller操作如下所示:
<AcceptVerbs(HttpVerbs.Post)>
Function EditSponsorPercs(ByVal SponPercModel As PercsCollection) As ActionResult
'' LOGIC HERE FOR processing model
''
''
' db.sponsorlevels.ApplyCurrentValues(y)
db.SaveChanges()
Return RedirectToAction("xxxxxxnsorInfo")
End Function
视图如下:
@ModelType xxxxxxx.PercsCollection
@Code
ViewData("Title") = "EditSponsorPercs"
End Code
@Using Html.BeginForm()
@<fieldset>
<table style="width: 100%">
<tr><td>@Html.ActionLink("Add Benefit", "AddSponBen", New With {.id = model.persCollections.ElementAt(0).idSponLevel})</td></tr>
<tr><th style="width: 90%">Benefits Descriptions</th><th>Order</th></tr>
@For i As Integer = 0 To Model.persCollections.Count - 1
Dim _i = i
@<tr><td style="min-height: 20px; width:80%">@Html.TextAreaFor(Function(f) f.persCollections.ElementAt(_i).sponLvlPercDesc, New With {.class = "item2"})</td><td>@Html.TextAreaFor(Function(f) f.persCollections.ElementAt(_i).percOrdering, New With {.class = "num1"})</td><td>@Html.ActionLink("Delete", "DeleteSponBen", New With {.id = Model.persCollections.ElementAt(0).idpercLevel})</td><td></td></tr>
Next
</table>
<p><input type="submit" name="Submit" /></p>
</fieldset>
End Using
模型设置如下:
Public Class PercsCollection
Private _percsCollections As New List(Of SponPercModel)
Public Property persCollections() As List(Of SponPercModel)
Get
Return _percsCollections
End Get
Set(ByVal value As List(Of SponPercModel))
_percsCollections = value
End Set
End Property
Public Class SponPercModel
Private _idpercLevel As Integer
Public Property idpercLevel() As Integer
Get
Return _idpercLevel
End Get
Set(ByVal value As Integer)
_idpercLevel = value
End Set
End Property
Private _sponLvlPercDesc As String
Public Property sponLvlPercDesc() As String
Get
Return _sponLvlPercDesc
End Get
Set(ByVal value As String)
_sponLvlPercDesc = value
End Set
End Property
Private _idSponLevel As Integer
Public Property idSponLevel() As Integer
Get
Return _idSponLevel
End Get
Set(ByVal value As Integer)
_idSponLevel = value
End Set
End Property
Private _percOrdering As Integer
Public Property percOrdering() As Integer
Get
Return _percOrdering
End Get
Set(ByVal value As Integer)
_percOrdering = value
End Set
End Property
End Class
End Class
渲染的HTML源代码如下所示:
<tr><td style="min-height: 20px; width:80%"><textarea class="item2" cols="20" id="sponLvlPercDesc" name="sponLvlPercDesc" rows="2">
...............</textarea><input id="sponLvlPercDesc" name="sponLvlPercDesc" type="hidden" value=".................." /></td><td><textarea class="num1" cols="20" id="percOrdering" name="percOrdering" rows="2">
1</textarea><input id="percOrdering" name="percOrdering" type="hidden" value="1" /></td><td><a href="/Admin/DeleteSponBen/1">Delete Sponsor Benefit</a></td><td></td></tr>
<tr><td style="min-height: 20px; width:80%"><textarea class="item2" cols="20" id="sponLvlPercDesc" name="sponLvlPercDesc" rows="2">
..................</textarea><input id="sponLvlPercDesc" name="sponLvlPercDesc" type="hidden" value=".................." /></td><td><textarea class="num1" cols="20" id="percOrdering" name="percOrdering" rows="2">
2</textarea><input id="percOrdering" name="percOrdering" type="hidden" value="2" /></td><td><a href="/Admin/DeleteSponBen/1">Delete Sponsor Benefit</a></td><td></td></tr>
<tr><td style="min-height: 20px; width:80%"><textarea class="item2" cols="20" id="sponLvlPercDesc" name="sponLvlPercDesc" rows="2">
..................</textarea><input id="sponLvlPercDesc" name="sponLvlPercDesc" type="hidden" value=".................." /></td><td><textarea class="num1" cols="20" id="percOrdering" name="percOrdering" rows="2">
3</textarea><input id="percOrdering" name="percOrdering" type="hidden" value="3" /></td><td><a href="/Admin/DeleteSponBen/1">Delete Sponsor Benefit</a></td><td></td></tr>
<tr><td style="min-height: 20px; width:80%"><textarea class="item2" cols="20" id="sponLvlPercDesc" name="sponLvlPercDesc" rows="2">
..................</textarea><input id="sponLvlPercDesc" name="sponLvlPercDesc" type="hidden" value=".................." /></td><td><textarea class="num1" cols="20" id="percOrdering" name="percOrdering" rows="2">
4</textarea><input id="percOrdering" name="percOrdering" type="hidden" value="4" /></td><td><a href="/Admin/DeleteSponBen/1">Delete Sponsor Benefit</a></td><td></td></tr>
<tr><td style="min-height: 20px; width:80%"><textarea class="item2" cols="20" id="sponLvlPercDesc" name="sponLvlPercDesc" rows="2">
..................</textarea><input id="sponLvlPercDesc" name="sponLvlPercDesc" type="hidden" value="..................(Submit your logo)" /></td><td><textarea class="num1" cols="20" id="percOrdering" name="percOrdering" rows="2">
5</textarea><input id="percOrdering" name="percOrdering" type="hidden" value="5" /></td><td><a href="/Admin/DeleteSponBen/1">Delete Sponsor Benefit</a></td><td></td></tr>
<tr><td style="min-height: 20px; width:80%"><textarea class="item2" cols="20" id="sponLvlPercDesc" name="sponLvlPercDesc" rows="2">R..................</textarea><input id="sponLvlPercDesc" name="sponLvlPercDesc" type="hidden" value=".................." /></td><td><textarea class="num1" cols="20" id="percOrdering" name="percOrdering" rows="2">
6</textarea><input id="percOrdering" name="percOrdering" type="hidden" value="6" /></td><td><a href="/Admin/DeleteSponBen/1">Delete Sponsor Benefit</a></td><td></td></tr>
视图填充正常,但在提交时,模型将返回空...打开想法..