0
我试图使用HTML表单向服务器提交潜在客户信息。首先,我有一个主要视图,它包含一个确定我们想要提交多少客户的ajax表单。提交后,它将填充所需数量的输入的部分视图。例如HTML摘录了两个客户的标题:ASP MVC在局部视图问题中绑定IList
<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);
}
看起来我需要工作在我的调试技能大声笑。我使用了开发者控制台并且正在传递。我将断点移到了没有在代码中直接操作的地方,并且它在那里。似乎我失去了它后来下线(我的控制器打电话给经纪人是(我猜)造成的问题)。 –