In MVC, when I post the form, the model data is not posted, I can see the input fields properly named using inspect element. Please help me out....
Following is my code
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
In parialview I have following code
@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>
and in controller, I am using
<HttpPost()> _
Function _saveActivities(lModel As Models.ProjectModel) As ActionResult
End Function
Following is my model.
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