我有两个模型,有。
public class CreateAssignmentViewModel {
...
public List<CreateAssignmentSelectedItem> SelectedItems { get; set; }
}
public class CreateAssignmentSelectedItem {
...
}
现在我有一个视图 where contains CreateAssignmentViewModel
,正如您在上面看到的那样,这个类包含一个属性 where is aList<CreateAssignmentSelectedItem>
@model Contoso.MvcApplication.Models.Assignment.CreateAssignmentViewModel
@{
ViewBag.Title = "Create Assignment";
...
}
@using (Html.BeginForm()) {
...
}
在里面Html.BeginForm
,我有一个局部视图。在其中我有一个使用 ajax 的按钮,用于更新部分视图。
查看以下事件。数据在哪里:我不知道要输入什么才能仅访问该属性SelectedItems
var addQuestionToAssignmentContent = function (questionId)
{
$.ajax({
url: "/Assignment/AddItemToAssignmentContent",
type: "post",
data: { model: $(this).serialize() /* HERE I DON'T KNOW TO ACCESS THE */, itemId: questionId },
success: function (response) {
var $target = $("#assignmentContent");
var $newHtml = response;
$target.replaceWith($newHtml);
}
});
};
public ActionResult AddItemToAssignmentContent(List<CreateAssignmentSelectedItem> model, string itemId)
{
...
PartialView(..);
}
如何只传递方法中的对象?