Click here to Skip to main content
15,891,777 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am sending a collection from my partial view to post action but it is always null please help
my partial view
@model TestData

@using (Html.BeginForm("Test", "Admin", FormMethod.Post, new { @id = "frm" }))
{
@Html.LabelFor(m=> m.name)
<table style="height: 300px; width: 400px; vertical-align: top">
@foreach (var Area in Model.Courses)
{
<tr>
<td>
@Html.LabelFor(m=> Area.Area)
</td>

<td>
@Html.CheckBoxFor(modelItem => Area.IsActive)
</td>
</tr>
}
</table>
<input type="submit" value="click" />
}
my main view

<td id="TestData" valign="top"></td>
function Selected(e) {
var data = $("#classList option:selected")
var val = data.val();
// $('#TestData').load('/Admin/_CoursesByClassification/?id=' + val);
$.ajax({
type: "GET",
url: "/Admin/_CoursesByClassification/?id=" + val,
dataType: "html",
success: function (evt) {
$('#TestData').html(evt);
},
error: function (req, status, error) {
alert("Error!Occured");
}
});

}
public ActionResult _CoursesByClassification(string id)
{
List<ViewModels.AreaVM> modelList = new List<ViewModels.AreaVM>();
ViewModels.AreaVM area = new ViewModels.AreaVM() { Area = "area1", IsActive = true };
ViewModels.AreaVM area2 = new ViewModels.AreaVM() { Area = "area2", IsActive = true };
ViewModels.AreaVM area3 = new ViewModels.AreaVM() { Area = "area3", IsActive = false };
modelList.Add(area);
modelList.Add(area2);
modelList.Add(area3);
var m = new TestData() { Courses = modelList , name="Tauseef"};
return PartialView("_Courses", m);
}
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900