Yani .. List
sahip bir sınıf var. Bu şekilde alacaksınızListaged olarak onay kutusu ile IPagedList Ciltleme
[HttpGet]
[Authorize(Roles="user")]
[CustomChecker]
public ActionResult Index(int? page, int id=0)
{
EmployeeContext emp = new EmployeeContext();
student st = emp.students.Single(x=>x.id ==id);
@ViewBag.id = st.id;
return View(st.subjSel.ToPagedList(page ?? 1, 4));
}
Sonra Görünüm: aşağıda kodu gibi görünümüne geçmek
@using PagedList;
@using PagedList.Mvc;
@model PagedList<MvcApplication6.Models.subject>
<div style="font-family:Arial">
<fieldset>
<legend><h3>Open Classes</h3></legend>
@using (Html.BeginForm("Test", "Enrollment"))
{
<input type="hidden" name="id" value="@ViewBag.id" />
<table border="1">
<tr>
<th>@Html.LabelFor(model => model[0].subj)</th>
<th>@Html.LabelFor(model => model[0].days)</th>
<th>@Html.LabelFor(model => model[0].cstart)</th>
<th>@Html.LabelFor(model => model[0].cend)</th>
<th>@Html.LabelFor(model => model[0].professor)</th>
<th>@Html.LabelFor(model => model[0].units)</th>
<th>@Html.CheckBox("test") Select all</th>
</tr>
@for (int i = 0; i < Model.Count; i++)
{
<tr>
@Html.HiddenFor(model => model[i].id)
<td>
@Html.DisplayFor(m => m[i].subj)
@Html.HiddenFor(m => m[i].subj)
</td>
<td>
@Html.DisplayFor(m => m[i].days)
@Html.HiddenFor(m => m[i].days)
</td>
<td>
@Html.DisplayFor(m => m[i].cstart)
@Html.HiddenFor(m => m[i].cstart)
</td>
<td>
@Html.DisplayFor(m => m[i].cend)
@Html.HiddenFor(m => m[i].cend)
</td>
<td>
@Html.DisplayFor(m => m[i].professor)
@Html.HiddenFor(m => m[i].professor)
</td>
<td>
@Html.DisplayFor(m => m[i].units)
@Html.HiddenFor(m => m[i].units)
</td>
<td>
@Html.CheckBoxFor(m => m[i].isSelected)
</td>
</tr>
}
</table>
<br />
<br />
<table>
<tr><td align="center" width="500px"></td></tr>
<tr>
<td align="center" width="500px">
<input type="submit" value="submit" /> | <input type="button" value="clear" />
</td>
</tr>
</table>
<br />
<br />
}
</fieldset>
</div>
@Html.PagedListPager(Model, page => Url.Action("Index", "Enrollment", new { page, id = Request.QueryString["id"] }))
Benim sorunum bu [0].subj
ve bu won'dan gibi icra edileceğini olduğu Bağlanmama izin ver çünkü name[0].subj
gibi bir şey olmalı.
Yeni yöntemler denedim ve denedim, bunları düzgün bir şekilde bağlama konusunda herhangi bir yol var mı? Ben Html Helpers
kullanmak istiyorum ve mümkün olduğunca, bu bölüm için özel bir yeniden uygulamak istemiyorum.
Bu, bağlı olmaları gereken işlevdir. Bu sınıf öğrenci List
(i IPagedList dönüştürülen tane)
[HttpPost]
[Authorize(Roles="user")]
public ActionResult Test(student st)
vardır Ve bu benim View
benziyor nasıl. Seçimler için CheckBoxFor
kullanıyorum.
Ekstra soru: Gezinmemi Nasıl yani çok çirkin görünüyor?
'a geri gönderin. [0] .subj' ('name [0] .subj' değil) olması gerekir. PagedList '' student' değil, bu, POST yönteminin IEnumerable '' student' değil olması gerektiği anlamına gelir. Alternatif olarak, POST yönteminde “öğrencinin” olmasını istiyorsanız, görünümdeki modelin “öğrenci” olması gerekir. –
Ancak 'student' için herhangi bir denetim oluşturmuyorsunuz ('id' özelliği dışında), böylece bir yol değeri olarak kolayca eklenebilecek ve böylece –
POST yöntemine sahip olacaksınız. Yani eğer [0] .subj' o zaman IEnumerable 'olmalıdır? –