传递到字典中的模型项的类型是' System.Collections.Generic.List`1 [AVASupplierPortal.Models.PurchaseOrder]'

时间:2018-02-13 16:37:11

标签: c# .net asp.net-mvc visual-studio model-view-controller

在我的MVC项目中,我在返回特定内容时遇到错误 System.InvalidOperationException:传递到字典中的模型项的类型为' System.Collections.Generic.List`1 [AVASupplierPortal.Models.PurchaseOrder]',但此字典需要类型为&#的模型项39; AVASupplierPortal.Models.PurchaseOrder'

如何显示要查看的列表数据?

    @model AVASupplierPortal.Models.PurchaseOrder

@{
    ViewBag.Title = "Edit";
}


@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()

    <div class="form-horizontal">
        <hr />
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
        @Html.HiddenFor(model => model.POID)

        <div class="shipment_innercontainer">

            <div class="shipe_header-details">
                <div class="shipe_header_list">
                    <div class="shipe_list">
                        <label>PO #</label>
                        <label>@Html.DisplayFor(model => model.PONumber)</label>
                    </div>
                    <div class="shipe_list">
                        <label>Carrier</label>
                        <label>@Html.DisplayFor(model => model.Carrier)</label>
                    </div>
                    <div class="shipe_list">
                        <label>Shipment Type</label>
                        <label><span class="ship_icon shippingicons icontext">@Html.DisplayFor(model => model.ShipmentType)</span></label>
                    </div>
                </div>
                <div class="shipe_header_list">
                    <div class="shipe_list">
                        <label>PO Date</label>
                        <label> @Convert.ToString(string.Format("{0:dd/MM/yyyy}", Model.PODate))</label>
                    </div>
                    <div class="shipe_list">
                        <label>Status</label>
                        <label>@Html.DisplayFor(model => model.POStatusDetails.OrderByDescending(p => p.StatusID).First().MSTPOStatu.POStatus)</label>
                    </div>
                    <div class="shipe_list">
                        <label>Branch Name</label>
                        <label>@Html.DisplayFor(model => model.BranchName)</label>
                    </div>

                </div>
                <div class="shipe_header_list">
                    <div class="shipe_list">
                        <label>Retailer</label>
                        <label>@Html.DisplayFor(model => model.MSTRetailerDetail.RetailerName)</label>
                    </div>
                    <div class="shipe_list">
                        <label>File #</label>
                        <label>@Html.DisplayFor(model => model.FileDetail)</label>
                    </div>
                    <div class="shipe_list">
                        <label>Customer #</label>
                        <label>@Html.DisplayFor(model => model.Customer)</label>
                    </div>
                </div>
            </div>
            <div class="Options-Header">
                <div>
                    <div class="Options"> <a href="#"> <span><img src="~/Content/Images/Save_Icon.PNG" alt="Save" /></span> <span>Save</span> </a> </div>
                    <div class="Options"> <a href="#"> <span><img src="~/Content/Images/Print_Icon.PNG" alt="Print" /></span> <span>Print</span> </a> </div>
                    <div class="Options"> <a href="#"> <span><img src="~/Content/Images/History_Icon.PNG" alt="History" /></span> <span>History</span> </a> </div>
                </div>
            </div>
            <div class="TabsContainer">
                <ul>
                    <li class="Tab-ISF Tab-Active"><a href="#">Purchase Order</a></li>
                    <li class="Tab-BaseFile"><a href="#">Acknowledgement</a></li>
                    <li class="Tab-7501"><a href="#">ASN</a></li>
                    <li class="Tab-DeliverOrder"><a href="#">Invoice</a></li>
                </ul>
            </div>
            <div class="shipment_forms">
                <div class="Content_Heading">
                    <h1>Purchase Order Details</h1>
                </div>
                <form>
                    <div class="PersonalFormFields">
                        <div class="EPE_FORM_Container">
                            <div class="FORM_PANEL">
                                <div class="FORM_FIELD"> <span>Requisition Number</span> </div>
                                <div class="FORM_ENTRY">
                                    <label>@Html.DisplayFor(model => model.RequistionNumber) </label>
                                    <input type="text" value=@Html.DisplayFor(model => model.RequistionNumber) style="display:none" />
                                    <div class="FORM_ERROR"> <span>Please Enter Requisition No</span> </div>
                                </div>
                            </div>
                            <div class="FORM_PANEL">
                                <div class="FORM_FIELD"> <span>Contact Name</span> </div>
                                <div class="FORM_ENTRY">
                                    <label>@Html.DisplayFor(model => model.ContactName)</label>
                                    <input type="text" value=@Html.DisplayFor(model => model.ContactName) style="display:none" />
                                    <div class="FORM_ERROR"> <span>Please Enter Contact Name</span> </div>
                                </div>
                            </div>
                            <div class="FORM_PANEL">
                                <div class="FORM_FIELD"> <span>Due Date</span> </div>
                                <div class="FORM_ENTRY Date_Pick">
                                    <label>@Convert.ToString(string.Format("{0:dd/MM/yyyy}", Model.DueDate))</label>
                                    <input type="text" id="datepicker" value=@Html.DisplayFor(model => model.DueDate) style="display:none" />
                                    <span class="date_icon" style="display:none"></span>
                                    <div class="FORM_ERROR"> <span>This Must Be Field Out</span> </div>
                                </div>
                            </div>
                        </div>
                        <div class="EPE_FORM_Container">
                            <div class="FORM_PANEL">
                                <div class="FORM_FIELD"> <span>Status</span> </div>
                                <div class="FORM_ENTRY">
                                    <select id="test" class="speed">
                                        <option>Acknowledged</option>
                                        <option>ASN Sent</option>
                                        <option>Invoice Sent</option>
                                    </select>
                                    <div class="FORM_ERROR"> <span>This Must Be Field Out</span> </div>
                                </div>
                            </div>
                            <div class="FORM_PANEL">
                                <div class="FORM_FIELD"> <span>Tracking Number</span> </div>
                                <div class="FORM_ENTRY">
                                    <label>@Html.DisplayFor(model => model.TrackingNumber)</label>
                                    <input type="text" value=@Html.DisplayFor(model => model.TrackingNumber) style="display:none" />
                                </div>
                            </div>
                            <div class="FORM_PANEL">
                                <div class="FORM_FIELD"> <span>Phone</span> </div>
                                <div class="FORM_ENTRY">
                                    <label>@Html.DisplayFor(model => model.Phone)</label>
                                    <input type="text" value=@Html.DisplayFor(model => model.Phone) style="display:none" />
                                </div>
                            </div>
                        </div>
                        <div class="EPE_FORM_Container">
                            <div class="FORM_PANEL">
                                <div class="FORM_FIELD"> <span>Fax</span> </div>
                                <div class="FORM_ENTRY">
                                    <label>@Html.DisplayFor(model => model.Fax)</label>
                                    <input type="text" value=@Html.DisplayFor(model => model.Fax) style="display:none" />
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <div class="shipment_forms">
                <div class="Content_Heading">
                    <h1>Address Information</h1>
                </div>
                <form>
                    <div class="PersonalFormFields">
                        <div class="EPE_FORM_Container">
                            <div class="FORM_PANEL">
                                <div class="FORM_FIELD"> <span>Bill To</span> </div>
                                <div class="FORM_ENTRY">
                                    <select class="speed">
                                        <option>Select</option>
                                        <option>Administrator</option>
                                    </select>
                                </div>
                            </div>
                            <div class="FORM_PANEL">
                                <div class="FORM_FIELD"> <span>Billing Address</span> </div>
                                <div class="FORM_ENTRY">
                                    <label>@Html.DisplayFor(model => model.POBillToAddress.POBillingAddress)</label>
                                    <textarea style="display:none"></textarea>
                                </div>
                            </div>

                            <div class="FORM_PANEL">
                                <div class="FORM_FIELD"> <span>Billing City</span> </div>
                                <div class="FORM_ENTRY">
                                    <label>@Html.DisplayFor(model => model.POBillToAddress.POBillingCity)</label>
                                    <input type="text" value="" style="display:none" />
                                </div>
                            </div>
                        </div>
                        <div class="EPE_FORM_Container">
                            <div class="FORM_PANEL">
                                <div class="FORM_FIELD"> <span>Billing State</span> </div>
                                <div class="FORM_ENTRY">
                                    <label>@Html.DisplayFor(model => model.POBillToAddress.POBillingState)</label>
                                    <input type="text" value="" style="display:none" />
                                </div>
                            </div>
                            <div class="FORM_PANEL">
                                <div class="FORM_FIELD"> <span>Billing Code</span> </div>
                                <div class="FORM_ENTRY">
                                    <label>@Html.DisplayFor(model => model.POBillToAddress.POBillingCode)</label>
                                    <input type="text" value="" style="display:none" />
                                </div>
                            </div>
                            <div class="FORM_PANEL">
                                <div class="FORM_FIELD"> <span>Billing Country</span> </div>
                                <div class="FORM_ENTRY">
                                    <label>@Html.DisplayFor(model => model.POBillToAddress.POBillingCountry)</label>
                                    <input type="text" value="" style="display:none" />
                                </div>
                            </div>


                        </div>
                        <div class="EPE_FORM_Container">
                            <div class="FORM_PANEL">
                                <div class="FORM_FIELD"> <span>Deliver To</span> </div>
                                <div class="FORM_ENTRY">
                                    <input type="text" value="" style="display:none" />
                                </div>
                            </div>
                            <div class="FORM_PANEL">
                                <div class="FORM_FIELD"> <span>Shipping Address</span> </div>
                                <div class="FORM_ENTRY">
                                    <label>@Html.DisplayFor(model => model.POShipToAddress.POShippingAddress)</label>
                                    <textarea style="display:none"></textarea>
                                </div>
                            </div>

                            <div class="FORM_PANEL">
                                <div class="FORM_FIELD"> <span>Shipping City</span> </div>
                                <div class="FORM_ENTRY">
                                    <label>@Html.DisplayFor(model => model.POShipToAddress.POShippingCity)</label>
                                    <input type="text" value="" style="display:none" />
                                </div>
                            </div>
                        </div>
                        <div class="EPE_FORM_Container">
                            <div class="FORM_PANEL">
                                <div class="FORM_FIELD"> <span>Shipping State</span> </div>
                                <div class="FORM_ENTRY">
                                    <label>@Html.DisplayFor(model => model.POShipToAddress.POShippingState)</label>
                                    <input type="text" value="" style="display:none" />
                                </div>
                            </div>
                            <div class="FORM_PANEL">
                                <div class="FORM_FIELD"> <span>Shipping Code</span> </div>
                                <div class="FORM_ENTRY">
                                    <label>@Html.DisplayFor(model => model.POShipToAddress.POShippingCode)</label>
                                    <input type="text" value="" style="display:none" />
                                </div>
                            </div>
                            <div class="FORM_PANEL">
                                <div class="FORM_FIELD"> <span>Shipping Country</span> </div>
                                <div class="FORM_ENTRY">
                                    <label>@Html.DisplayFor(model => model.POShipToAddress.POShippingCountry)</label>
                                    <input type="text" value="" style="display:none" />
                                </div>
                            </div>


                        </div>
                    </div>
                </form>
            </div>
            <div class="sf15_sf20_tables">
                <div class="Bill_Heading">
                    <h1>Product Details</h1>
                </div>
                <div class="sf_container Bill_Info">
                    <div class="sf_table-part deliverT">
                        <table class="table ProjectTable deliverytable">
                            <tr>
                                <th>Product</th>
                                <th>Retailer Product Number</th>
                                <th>Notes</th>
                                <th>Qty</th>
                                <th>Unit Cost</th>
                                <th>Retailer Price</th>
                                <th>Discount(%)</th>
                                <th>Total</th>
                                <th>Action</th>
                            </tr>
                            @foreach (var lineItems in Model.POLineItemDetails)
                            {
                            <tr>
                                <td>@Html.DisplayFor(modelItem => lineItems.ItemDescription)</td>
                                <td>@Html.DisplayFor(modelItem => lineItems.RetailerItemNumber)</td>
                                <td>@Html.DisplayFor(modelItem => lineItems.Notes)</td>
                                <td>@Html.DisplayFor(modelItem => lineItems.Quantity)</td>
                                <td>@Html.DisplayFor(modelItem => lineItems.UnitCost)</td>
                                <td>@Html.DisplayFor(modelItem => lineItems.RetailerPrice)</td>
                                <td>@Html.DisplayFor(modelItem => lineItems.Discount)</td>
                                <td>@Html.DisplayFor(modelItem => lineItems.Total)</td>
                                <td><span class="delete_icon1"></span></td>
                            </tr>
                            }
                        </table>
                    </div>
                </div>
            </div>
            <div class="form-group" style="display:none">
                @Html.LabelFor(model => model.PONumber, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.PONumber, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.PONumber, "", new { @class = "text-danger" })
                </div>
            </div>
            <div class="shipment_forms">
                <div class="Content_Heading">
                    <h1>Terms & Conditions</h1>
                </div>
                <div class="PersonalFormFields">
                    <div class="EPE_FORM_Container">

                        <div class="FORM_PANEL full-width-textarea">
                            <div class="FORM_FIELD"> <span>Terms & Conditions</span> </div>
                            <div class="FORM_ENTRY">
                                <div class="form-group">
                                    <div class="col-md-10">
                                        @Html.EditorFor(model => model.TermsAndConditions, new { htmlAttributes = new { @class = "form-control" } })
                                    </div>
                                </div>
                            </div>
                        </div>

                    </div>

                </div>
            </div>
            <div class="shipment_forms">
                <div class="Content_Heading">
                    <h1>Description Informations</h1>
                </div>

                <div class="PersonalFormFields">
                    <div class="EPE_FORM_Container">

                        <div class="FORM_PANEL full-width-textarea">
                            <div class="FORM_FIELD"> <span>Description</span> </div>
                            <div class="FORM_ENTRY">
                                <div class="form-group">
                                    <div class="col-md-10">
                                        @Html.EditorFor(model => model.Description, new { htmlAttributes = new { @class = "form-control" } })
                                    </div>
                                </div>
                            </div>
                        </div>

                    </div>

                </div>

            </div>

            <div class="SearchButtonAdvance formbutton">
                <div class="form-group">
                    <div class="col-md-offset-2 col-md-10">
                        <input type="submit" value="Save" class="btn btn-default" />
                    </div>
                </div>
            </div>
        </div>
    </div>
}

@*<div>
        @Html.ActionLink("Back to List", "Index")
    </div>*@

<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script src="~/Scripts/jquery.validate.min.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>

1 个答案:

答案 0 :(得分:0)

在控制器中: 当你这样做

import threading
import time

def timeout():

    for i in range(10):
      time.sleep(0.1)
    print('stop all bla loops now')

    billy = 'timeout'


def loops():

  for i in range(5):
    time.sleep(0.1)
    print('loop1')

  billy = 'loop1 done'

  for i in range(5):
    time.sleep(0.1)
    print('loop2')

  billy = 'loop2 done'

  for i in range(5):
    time.sleep(0.1)
    print('loop3')

  billy = 'loop3 done'



billy = 'cool'

loops = threading.Thread(target=loops).start()
timeout = threading.Thread(target=timeout).start()

在视图中

View(*THIS IS YOUR MODEL*)

这两件事需要匹配,否则你会得到那个错误。像oppassum说的那样,阅读错误:

@model *THIS IS YOUR MODEL*

列表与单项。

欢迎使用StackOverflow:)