在 MVC 中,当我 post 表单时,模型数据未被 post 编辑,我可以看到使用检查元素正确命名的输入字段。寻找建议
In MVC, when I post the form, the model data is not posted, I can see the input fields properly named using inspect element. Looking for suggestions
在 MVC 中,当我 post 表单时,未 post 编辑模型数据,我可以看到使用检查元素正确命名的输入字段。请帮帮我....
以下是我的代码
Using (Html.BeginForm("_saveActivities", "Projects", FormMethod.Post, New With {.name = "frmActivity", .id = "frmActivity", .enctype = "multipart/form-data"}))
@Html.HiddenFor(Function(X) X.Project.ID)
@<table class="formTable">
<thead>
<tr>
<td colspan="2">Project Activties</td>
</tr>
</thead>
<tr>
<td colspan="2" style=" text-align:right; background-color:#DFDFDF">
To add new row click
<a href="#?" onclick="addActivityRow(@Model.Project.ID)">click here</a>
</td>
</tr>
<tr>
<td colspan="2" style=" background-color:#DFDFDF">
<table id="tblProjectActivities" style=" width:100%">
<tr>
<td style="width:1px;"></td>
<td style=" width:300px;" >Activity</td>
<td style=" width:110px;" >Start Date</td>
<td style=" width:110px;" >End Date</td>
<td style=" width:15px;"></td>
</tr>
@For Each Item In Model.ProjectActivities
Html.RenderPartial("_ProjectFormActivitiesRow", Item)
Next
</table>
</td>
</tr>
<tfoot>
<tr>
<td colspan="2">
<div id="buttonsActivityDiv" style=" position:relative; background-color:inherit; height:40px;">
<input type="submit" id="comActivity" value="Update Activities" class="k-button"/>
</div>
</td>
</tr>
</tfoot>
</table>
End Using
在 parialview 中我有以下代码
@ModelType Models.ProjectActivityItem
@code
Dim strID As String = Guid.NewGuid.ToString
Dim strRowID As String = Guid.NewGuid.ToString
Dim strStateID As String = Guid.NewGuid.ToString("N")
End Code
<tr id="@strRowID">
<td>
<input type="hidden" name="ProjectActivties.Index" value="@strID" />
<input type="hidden" name="ProjectActivties[@(strID)].DetailEntity.ID" value="@Model.DetailEntity.ID"/>
<input type="hidden" name="ProjectActivties[@(strID)].DetailEntity.CreatedOn" value="@Model.DetailEntity.CreatedOn"/>
<input type="hidden" name="ProjectActivties[@(strID)].DetailEntity.CreatedBy" value="@Model.DetailEntity.CreatedBy"/>
<input type="hidden" name="ProjectActivties[@(strID)].DetailEntity.VersionEncoded" value="@Model.DetailEntity.VersionEncoded"/>
<input type="hidden" name="ProjectActivties[@(strID)].DetailEntity.ProjectID" value="@Model.DetailEntity.ProjectID"/>
<input type="hidden" id="@strStateID" name="ProjectActivties[@(strID)].DetailEntity.EntityState" value="@Model.DetailEntity.EntityState"/>
</td>
<td>@Html.TextBox("ProjectActivties[" & strID & "].DetailEntity.ActivityDescription", Model.DetailEntity.ActivityDescription, New With {.class = "inputAreaFull k-textbox"})</td>
<td>@Html.Kendo.DatePicker().Name("ProjectActivties[" & strID & "].DetailEntity.StartDate").Min(New DateTime(2000, 1, 1)).Value(Model.DetailEntity.StartDate).Format("dd-MMM-yyyy").HtmlAttributes(New With {.style = "width:110px"})</td>
<td>@Html.Kendo.DatePicker().Name("ProjectActivties[" & strID & "].DetailEntity.EndDate").Min(New DateTime(2000, 1, 1)).Value(Model.DetailEntity.EndDate).Format("dd-MMM-yyyy").HtmlAttributes(New With {.style = "width:110px"})</td>
<td>
<img src="@Url.Content("/Content/delete_icon.png")" onclick="removeProjectActivity('@strRowID','@strStateID')" style ="cursor:pointer" title="Delete Detail"/>
</td>
</tr>
在控制器中,我正在使用
<HttpPost()> _
Function _saveActivities(lModel As Models.ProjectModel) As ActionResult
End Function
以下是我的模型。
Public Class ProjectActivity
Public Property ID As Int64
Public Property ProjectID As Int32
Public Property ActivityDescription As String
Public Property StartDate As DateTime
Public Property EndDate As DateTime
Public Property CreatedOn As DateTime
Public Property CreatedBy As Int32
Public Property ModifiedOn As DateTime
Public Property ModifiedBy As Int32
<NotMapped()> _
Public Property VersionEncoded As String
<NotMapped()> _
Public Property EntityState As EntityStateEnum
End Class
Public Class ProjectActivityItem
Inherits BaseObject
Public Property DetailEntity As Database.ProjectActivity
End Class
该模型未与控件的 Id 映射。它映射了名称。检查您呈现的控件名称和模型 属性 是否相同。
在 MVC 中,当我 post 表单时,未 post 编辑模型数据,我可以看到使用检查元素正确命名的输入字段。请帮帮我....
以下是我的代码
Using (Html.BeginForm("_saveActivities", "Projects", FormMethod.Post, New With {.name = "frmActivity", .id = "frmActivity", .enctype = "multipart/form-data"}))
@Html.HiddenFor(Function(X) X.Project.ID)
@<table class="formTable">
<thead>
<tr>
<td colspan="2">Project Activties</td>
</tr>
</thead>
<tr>
<td colspan="2" style=" text-align:right; background-color:#DFDFDF">
To add new row click
<a href="#?" onclick="addActivityRow(@Model.Project.ID)">click here</a>
</td>
</tr>
<tr>
<td colspan="2" style=" background-color:#DFDFDF">
<table id="tblProjectActivities" style=" width:100%">
<tr>
<td style="width:1px;"></td>
<td style=" width:300px;" >Activity</td>
<td style=" width:110px;" >Start Date</td>
<td style=" width:110px;" >End Date</td>
<td style=" width:15px;"></td>
</tr>
@For Each Item In Model.ProjectActivities
Html.RenderPartial("_ProjectFormActivitiesRow", Item)
Next
</table>
</td>
</tr>
<tfoot>
<tr>
<td colspan="2">
<div id="buttonsActivityDiv" style=" position:relative; background-color:inherit; height:40px;">
<input type="submit" id="comActivity" value="Update Activities" class="k-button"/>
</div>
</td>
</tr>
</tfoot>
</table>
End Using
在 parialview 中我有以下代码
@ModelType Models.ProjectActivityItem
@code
Dim strID As String = Guid.NewGuid.ToString
Dim strRowID As String = Guid.NewGuid.ToString
Dim strStateID As String = Guid.NewGuid.ToString("N")
End Code
<tr id="@strRowID">
<td>
<input type="hidden" name="ProjectActivties.Index" value="@strID" />
<input type="hidden" name="ProjectActivties[@(strID)].DetailEntity.ID" value="@Model.DetailEntity.ID"/>
<input type="hidden" name="ProjectActivties[@(strID)].DetailEntity.CreatedOn" value="@Model.DetailEntity.CreatedOn"/>
<input type="hidden" name="ProjectActivties[@(strID)].DetailEntity.CreatedBy" value="@Model.DetailEntity.CreatedBy"/>
<input type="hidden" name="ProjectActivties[@(strID)].DetailEntity.VersionEncoded" value="@Model.DetailEntity.VersionEncoded"/>
<input type="hidden" name="ProjectActivties[@(strID)].DetailEntity.ProjectID" value="@Model.DetailEntity.ProjectID"/>
<input type="hidden" id="@strStateID" name="ProjectActivties[@(strID)].DetailEntity.EntityState" value="@Model.DetailEntity.EntityState"/>
</td>
<td>@Html.TextBox("ProjectActivties[" & strID & "].DetailEntity.ActivityDescription", Model.DetailEntity.ActivityDescription, New With {.class = "inputAreaFull k-textbox"})</td>
<td>@Html.Kendo.DatePicker().Name("ProjectActivties[" & strID & "].DetailEntity.StartDate").Min(New DateTime(2000, 1, 1)).Value(Model.DetailEntity.StartDate).Format("dd-MMM-yyyy").HtmlAttributes(New With {.style = "width:110px"})</td>
<td>@Html.Kendo.DatePicker().Name("ProjectActivties[" & strID & "].DetailEntity.EndDate").Min(New DateTime(2000, 1, 1)).Value(Model.DetailEntity.EndDate).Format("dd-MMM-yyyy").HtmlAttributes(New With {.style = "width:110px"})</td>
<td>
<img src="@Url.Content("/Content/delete_icon.png")" onclick="removeProjectActivity('@strRowID','@strStateID')" style ="cursor:pointer" title="Delete Detail"/>
</td>
</tr>
在控制器中,我正在使用
<HttpPost()> _
Function _saveActivities(lModel As Models.ProjectModel) As ActionResult
End Function
以下是我的模型。
Public Class ProjectActivity
Public Property ID As Int64
Public Property ProjectID As Int32
Public Property ActivityDescription As String
Public Property StartDate As DateTime
Public Property EndDate As DateTime
Public Property CreatedOn As DateTime
Public Property CreatedBy As Int32
Public Property ModifiedOn As DateTime
Public Property ModifiedBy As Int32
<NotMapped()> _
Public Property VersionEncoded As String
<NotMapped()> _
Public Property EntityState As EntityStateEnum
End Class
Public Class ProjectActivityItem
Inherits BaseObject
Public Property DetailEntity As Database.ProjectActivity
End Class
该模型未与控件的 Id 映射。它映射了名称。检查您呈现的控件名称和模型 属性 是否相同。