2017-01-03 33 views
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); 
    } 

回答

0

我想添加評論,但我不能呢。

你看過瀏覽器中的Web開發者控制檯嗎?這個數組是否正確傳遞給請求?

什麼是VisualfilesSession

+0

看起來我需要工作在我的調試技能大聲笑。我使用了開發者控制檯並且正在傳遞。我將斷點移到了沒有在代碼中直接操作的地方,並且它在那裏。似乎我失去了它後來下線(我的控制器打電話給經紀人是(我猜)造成的問題)。 –