2
我正在創建我的第一個MVC應用程序,其中一個頁面需要列出數據庫中的一系列問題。我已經設定了產品型號:MVC 3 Webapp - Model Binder
public class Audit
{
public DateTime InspectionDate { get; set; }
public string Engineer { get; set; }
public List<AuditGroup> AuditGroups { get; set; }
}
public class AuditGroup
{
public string GroupName { get; set; }
public List<AuditQuestion> AuditQuestions { get; set; }
}
public class AuditQuestion
{
public string Group { get; set; }
public string Question { get; set; }
public string Answer { get; set; }
public string Comments { get; set; }
}
該機型包含解釋,我創建了一個名爲創建和填充在團體組和問題,而這些頁面上的顯示精細模型頁面。當我回答的問題(在文本框填寫),並按下提交按鈕,它調用控制器:
[HttpPost]
public ActionResult Create(Audit newAudit)
{
try
{
// TODO: Add insert logic here
return RedirectToAction("Index");
}
catch
{
return View();
}
}
的newAudit在工程師和檢驗日期數據,但粘合劑沒有在頁面上拿起名單。這是一個減少的版本我已經試圖去解決它:
@{
ViewBag.Title = "Audit";
Layout = "~/Views/Shared/_Layout.cshtml";
}
@model test.Models.Audit
<h2>
Audit</h2>
@using (Html.BeginForm())
{
<fieldset>
@foreach (var AuditGroups in Model.AuditGroups)
{
@Html.EditorFor(x=> AuditGroups.GroupName)
}
</fieldset>
<p>
<input type="submit" value="Create" />
</p>
}
所以在這裏我經歷的列表,並把它們在頁面上,但在提交列表爲空。有誰知道我要去哪裏?
總之,我正在做的是發送一個問題列表頁面,用戶填寫和提交答案,但我沒有得到任何列表的答案。
嗨,感謝您的快速響應,我已下載示例代碼http://ivanz.com/2011/06/16/editing-variable-length-reorderable-collections-in-asp-net-mvc-第1部分/如你所建議的,看起來像我所需要的。我會及時向大家發佈 ... – MartGriff