C# Asp.NETMVC编辑器模板和无限滚动
我有以下用于表数据的编辑器模板MyProjectViewModel.cshtmlC# Asp.NETMVC编辑器模板和无限滚动,c#,ajax,asp.net-mvc,editorfor,C#,Ajax,Asp.net Mvc,Editorfor,我有以下用于表数据的编辑器模板MyProjectViewModel.cshtml <div> <div> @Html.CheckBoxFor(model => model.Selected) </div> <div> for (int i = 1; i < @Model.TypeList.Count; i++) {
<div>
<div>
@Html.CheckBoxFor(model => model.Selected)
</div>
<div>
for (int i = 1; i < @Model.TypeList.Count; i++)
{
<p id="@Model.TypeList[i].ID" >@Model.TypeList[i].Name</p>
}
</div>
@Html.HiddenFor(model => model.ID)
@Html.HiddenFor(model => model.Name)
</div>
在这里,即使我能够附加如何可能,我会得到之前选择的项目和新的一个发布时。请指导我。我看到您提供的代码的唯一问题是,您试图将部分视图作为JSON返回。删除对
Json
的调用,只需返回PartialView(…)
。那么,你应该是金色的
至于不返回重复项,您需要将其视为实际的寻呼机。无限卷轴不仅返回10个新的随机项,而且不使用分页链接来分页数据。因此,当您发送AJAX请求时,您需要传递当前所在的“页面”,并使用该页面确定如何对返回的数据进行分割。您可以使用LINQ帮助程序(如Skip
和Take
)手动完成,但您可能会发现使用第三方库(如。这取决于你
<div id="loadDynamic">
@Html.EditorFor(model => model.NewItem)
</div>
public ActionResult InfinateScroll(string lastID, string prjID)
{
//Querying DB to get List<Model>
//Not sure how to get the Editor Template here
// Tried with following, though it is not the one I needed
return Json(PartialView("~/Views/MyView/EditorTemplates/MyProjectViewModel.cshtml", model[0]));
}
$a.ajax({
type: "POST",
url: '@Url.Action("InfinateScroll", "Project")',
data: values,
traditional: true,
dataType: 'html',
cache: false,
success: function (data) {
$("#loadDynamic").append(data);
$("#loadingDiv").hide();
},
});