2014-02-08 33 views
0

對我的MVC應用程序的要求是存儲銀行事務。Modal上的可變大小列表

交易對象,包含交易行。

交易對象可以有一個或多個交易行。交易行中的值總和,併成爲交易的總金額。

當用戶創建一個新的交易時,將顯示一個單獨的交易行,並帶有一個Add按鈕。如果他們點擊添加,則會出現一個新的交易行,並顯示另一個添加按鈕。所以他們可以添加儘可能多的線。

我發送到視圖的模型具有列表行屬性,並且默認添加了一行。

我剛剛添加了10行(不會超過10.99%的時間,只有一行),然後只在視圖上隱藏行。但這看起來很骯髒。有沒有辦法處理這個 - 客戶端,添加項目到我的名單<>時,點擊添加按鈕?

當前狡猾代碼:

<div class="form-group"> 
    <label for="cmbCategory0" class="col-lg-1 control-label">Category:</label> 
    <div class="col-lg-3"> 
     @Html.DropDownListFor(x => x.Transaction.TransactionLines[0].CategoryId, 
            new SelectList(Model.TransactionReferences.Categories, "Value", "Text", Model.Transaction.TransactionLines[0].CategoryId), "Select one", 
            new { @onchange = "populateSubCategory(0)", @class = "cmbCategory0 form-control" }) 
    </div> 
    <div class="col-lg-3"> 
     @Html.DropDownListFor(x => x.Transaction.TransactionLines[0].SubCategoryId, 
            new SelectList(Model.TransactionReferences.SubCategories, "Value", "Text", Model.Transaction.TransactionLines[0].SubCategoryId), "Select one", 
            new { @class = "cmbSubCategory0 form-control" }) 
    </div> 
    <div class="col-lg-2"> 
     @Html.DropDownListFor(x => x.Transaction.TransactionLines[0].CostCentreId, 
            new SelectList(Model.TransactionReferences.CostCentres, "Value", "Text", Model.Transaction.TransactionLines[0].CostCentreId), "None", 
            new { @class = "cmbCostCentre0 form-control" }) 
    </div> 
    <label for="txtAmount0" class="col-lg-1 control-label">Amount:</label> 
    <div class="col-lg-1"> 
     @Html.TextBoxFor(x => x.Transaction.TransactionLines[0].Amount, new { @class = "txtAmount form-control input-money", @placeholder = "Amount", @type = "number", @min = 0, @step = "any" }) 
    </div> 
    <div class="col-lg-1"> 
     <a class="btn btn-info btnadd0" onclick="showSplit(0)">Add</a> 
    </div> 

</div> 


<div class="form-group row1 hide"> 
    <label for="cmbCategory1" class="col-lg-1 control-label">Category:</label> 
    <div class="col-lg-3"> 
     @Html.DropDownListFor(x => x.Transaction.TransactionLines[1].CategoryId, 
     new SelectList(Model.TransactionReferences.Categories, "Value", "Text", Model.Transaction.TransactionLines[1].CategoryId), "Select one", 
            new { @onchange = "populateSubCategory(1)", @class = "cmbCategory1 form-control" }) 
    </div> 
    <div class="col-lg-3"> 
     @Html.DropDownListFor(x => x.Transaction.TransactionLines[1].SubCategoryId, 
     new SelectList(Model.TransactionReferences.SubCategories, "Value", "Text", Model.Transaction.TransactionLines[1].SubCategoryId), "Select one", 
            new { @class = "cmbSubCategory1 form-control" }) 
    </div> 
    <div class="col-lg-2"> 
     @Html.DropDownListFor(x => x.Transaction.TransactionLines[1].CostCentreId, 
     new SelectList(Model.TransactionReferences.CostCentres, "Value", "Text", Model.Transaction.TransactionLines[1].CostCentreId), "None", 
            new { @class = "cmbCostCentre1 form-control" }) 
    </div> 
    <label for="txtAmount" class="col-lg-1 control-label">Amount:</label> 
    <div class="col-lg-1"> 
     @Html.TextBoxFor(x => x.Transaction.TransactionLines[1].Amount, new { @class = "txtAmount form-control input-money", @placeholder = "Amount", @type = "number", @min = 0, @step = "any" }) 
    </div> 
    <div class="col-lg-1"> 
     <a class="btn btn-info btnadd1" onclick="showSplit(1)">Add</a> 
    </div> 

</div> 

回答

0

肯定。

您爲線條創建了一個PartialView,並且在您的控制器中,您有一個方法將其作爲PartialView結果返回。在您看來,您使用@ Ajax.Action()幫助器來生成鏈接,同時在控制器中指定操作的名稱以返回部分視圖。

沒有你的實際代碼和視圖的片段,很難更具體,但這是廣泛的中風。

+0

謝謝埃裏克!聽起來很有希望。我現在正在添加'狡猾'的方式(查看代碼)。 – Craig