ASP MVC绑定IList出现部分视图问题



我正试图使用HTML表单向服务器提交潜在客户信息。首先,我有一个主视图,其中包含一个ajax表单,该表单决定了我们要提交的客户数量。提交后,它会用所需的输入量填充部分视图。两个客户标题的HTML摘录示例:

<td class="quoteStandardCell"><input name="sessionPriv.indi[0].title" tabindex="1" class="visualfilesinputtext" id="sessionPriv_indi_0__title" autofocus="autofocus" type="text" value=""></td>
<td class="quoteStandardCell"><input name="sessionPriv.indi[1].title" tabindex="11" class="visualfilesinputtext" id="sessionPriv_indi_1__title" autofocus="autofocus" type="text" value=""></td>

一切看起来都是正确生成的,但在提交客户信息时,它无法提交第一个客户的信息(indi[0])。当我在控制器中设置一个断点时,sessionPriv.indi只有1个人,该个人是第二组客户详细信息。

所以基本上,它不是提交第一组客户数据,我不知道为什么。任何指导都将不胜感激(对ASP来说还是相当新的)。我在下面包含了代码摘要。

主视图(CreatePrivate.aspx)

<%using (Ajax.BeginForm("indiView", "Visualfiles", null, new AjaxOptions { UpdateTargetId = "indiPartial", HttpMethod = "post", OnSuccess = "pageLoaded()" }, new { id = "genIndiForm" }))
{ %>
<table class="visualfilestable" id="indiHeadTable">
<tr>
<td colspan="4" class="quoteIndiHeader">Prospect Details</td>
</tr>
<tr class="quoteIndi quoteHeader">
<td class="quoteStandardCell">Prospect Type</td>
<td class="quoteStandardCell"><%: Html.DropDownListFor(n => Model.sessionPriv.type, new SelectList(privateType.types, "typeID", "typeName"), new { @class = "visualfilesinputdropdown", @onchange = "showIndiCount(this.value)", @id = "privateType" }) %></td>
<td class="quoteStandardCell IndiCountTR">Number of Individuals</td>
<td class="quoteStandardCell IndiCountTR"><%: Html.TextBoxFor(n => Model.sessionPriv.indiCount, new { @class = "visualfilesinputtext", @autofocus = "autofocus", type = "number", min = "2", max = "10", id = "indiCount" })%></td>
<td><input class="visualfilespostbutton" type="submit" id="Submitbutton" value="Continue" onclick="document.getElementById('visualfilesbusy').style.display = 'inline';" /></td>
</tr>
</table>
<%} %>
<%using (Html.BeginForm("createPrivate", "Visualfiles", FormMethod.Post, new { id = "createPrivForm", name = "privForm" }))
{ %>
<div class="indiPartial" id="indiPartial"></div>
<% } %>

部分视图(_indiData.ascx)

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<ASPOnline.Models.VisualfilesSession>" %>
<div class="indiWrapper">
<%if (Model != null)
{ %>
<% for (var i = 0; i < Model.sessionPriv.indiCount; i++)
{ %>
<div class="indiDiv">
<table class="indiTable">
<tr class="quoteIndiHeader">
<td colspan="8">Individual <%= i+1 %></td>
</tr>
<tr class="quoteIndi">
<td class="quoteStandardCell">Title</td>
<td class="quoteStandardCell"><%: Html.TextBoxFor(n => Model.sessionPriv.indi[i].title, new { @class = "visualfilesinputtext", @autofocus = "autofocus", tabindex=(i.ToString() + 1.ToString()).AsInt() })%></td>
<td class="quoteStandardCell">House Name / Flat</td>
<td class="quoteStandardCell"><%: Html.TextBoxFor(n => Model.sessionPriv.indi[i].houseName, new { @class = "visualfilesinputtext", @autofocus = "autofocus", tabindex=(i.ToString() + 4.ToString()).AsInt() })%></td>
<td class="quoteStandardCell">Locality</td>
<td class="quoteStandardCell"><%: Html.TextBoxFor(n => Model.sessionPriv.indi[i].locality, new { @class = "visualfilesinputtext", @autofocus = "autofocus", tabindex=(i.ToString() + 7.ToString()).AsInt() })%></td>
<td class="quoteStandardCell">Postcode</td>
<td class="quoteStandardCell"><%: Html.TextBoxFor(n => Model.sessionPriv.indi[i].postcode, new { @class = "visualfilesinputtext", @autofocus = "autofocus", tabindex=(i.ToString() + 10.ToString()).AsInt() })%></td>
</tr>

<tr class="quoteIndi">
<td class="quoteStandardCell">Given Name</td>
<td class="quoteStandardCell"><%: Html.TextBoxFor(n => Model.sessionPriv.indi[i].givenName, new { @class = "visualfilesinputtext", @autofocus = "autofocus", tabindex=(i.ToString() + 2.ToString()).AsInt() })%></td>
<td class="quoteStandardCell">House Number</td>
<td class="quoteStandardCell"><%: Html.TextBoxFor(n => Model.sessionPriv.indi[i].houseNumber, new { @class = "visualfilesinputtext", @autofocus = "autofocus", tabindex=(i.ToString() + 5.ToString()).AsInt() })%></td>
<td class="quoteStandardCell">Town</td>
<td class="quoteStandardCell"><%: Html.TextBoxFor(n => Model.sessionPriv.indi[i].town, new { @class = "visualfilesinputtext", @autofocus = "autofocus", tabindex=(i.ToString() + 8.ToString()).AsInt() })%></td>
<td class="quoteStandardCell">Daytime Contact</td>
<td class="quoteStandardCell"><%: Html.TextBoxFor(n => Model.sessionPriv.indi[i].daytimeContact, new { @class = "visualfilesinputtext", @autofocus = "autofocus", tabindex=(i.ToString() + 10.ToString()).AsInt() })%></td>
</tr>

<tr class="quoteIndi">
<td class="quoteStandardCell">Family Name</td>
<td class="quoteStandardCell"><%: Html.TextBoxFor(n => Model.sessionPriv.indi[i].familyName, new { @class = "visualfilesinputtext", @autofocus = "autofocus", tabindex=(i.ToString() + 3.ToString()).AsInt() })%></td>
<td class="quoteStandardCell">Street Name</td>
<td class="quoteStandardCell"><%: Html.TextBoxFor(n => Model.sessionPriv.indi[i].street, new { @class = "visualfilesinputtext", @autofocus = "autofocus", tabindex=(i.ToString() + 6.ToString()).AsInt() })%></td>
<td class="quoteStandardCell">County</td>
<td class="quoteStandardCell"><%: Html.TextBoxFor(n => Model.sessionPriv.indi[i].county, new { @class = "visualfilesinputtext", @autofocus = "autofocus", tabindex=(i.ToString() + 9.ToString()).AsInt() })%></td>
<td class="quoteStandardCell">Mobile Number</td>
<td class="quoteStandardCell"><%: Html.TextBoxFor(n => Model.sessionPriv.indi[i].mobile, new { @class = "visualfilesinputtext", @autofocus = "autofocus", tabindex=(i.ToString() + 10.ToString()).AsInt() })%></td>
</tr>
<tr class="quoteIndi">
<td class="quoteStandardCell">Email</td>
<td class="quoteStandardCell"><%: Html.TextBoxFor(n => Model.sessionPriv.indi[i].email, new { @class = "visualfilesinputtext", @autofocus = "autofocus", tabindex=(i.ToString() + 10.ToString()).AsInt() })%></td>
</tr>
</table>
</div>
<% } %>
<div class="indiPartialSubmit"><input class="visualfilespostbutton" type="submit" value="Create Private" /></div>
<% } %>
</div>

模型数据

public class individual
{
// Name
public string title { get; set; }
public string givenName { get; set; }
public string familyName { get; set; }
// Address Details
public string houseName { get; set; }
public string houseNumber { get; set; }
public string street { get; set; }
public string locality { get; set; }
public string town { get; set; }
public string county { get; set; }
public string postcode { get; set; }
// Contact Details
public string daytimeContact { get; set; }
public string mobile { get; set; }
public string email { get; set; }
public individual() {
title = "";
givenName = "";
familyName = "";
houseName = "";
street = "";
locality = "";
town = "";
county = "";
postcode = "";
daytimeContact = "";
mobile = "";
email = "";
}
}
public class priv
{
public int type { get; set; }   // Individual/Couple/Group
public int indiCount { get; set; }
public string role { get; set; }
public IList<individual> indi { get; set; }
public priv()
{
type = 0;
indiCount = 0;
role = "";
}
}

控制器

[HttpPost]
public ActionResult createPrivate(VisualfilesSession viewSession)
{
return PartialView(getNextPage(viewSession, "createPrivate"), savedSession);
}

我想添加一个注释,但我还不能。

你看过浏览器中的web开发人员控制台吗?这个数组是否正确地传递给请求?

什么是VisualfilesSession

最新更新