我尝试使用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);
}
答案 0 :(得分:0)
我会添加评论,但我还不能。
您是否在浏览器中查看了Web开发人员控制台?这个数组是否正确传递给请求?
什么是VisualfilesSession
?