问题描述
我正在从我的局部视图中发送一个集合来发布动作,但它始终为null请帮助
我的局部视图
@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区域)
{
< tr>
< td> ;
@ Html.LabelFor(m => Area.Area)
< / td>
< td>
@ Html.CheckBoxFor(modelItem => Area.IsActive)
< / td>
< / tr>
}
< / table>
< input type =submitvalue =click/>
}
我的主要v iew
< td id =TestDatavalign =top>< / td>
功能选中(e) {
var data = $(#classList option:selected)
var val = data.val();
// $ (''#TestData'')。load(''/ Admin / _CoursesByClassification /?id =''+ val);
$ .ajax({
类型: GET,
url:/ Admin / _CoursesByClassification /?id =+ val,
dataType:html,
成功:function(evt){
$(''#TestData'')。html(evt);
},
错误:函数(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};
返回PartialView(_ Courses,m);
}
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);
}
推荐答案
这篇关于mvc局部视图模型被发送回服务器动作post方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!