C# 从类型';System.String';输入'';Y';失败,因为没有类型转换器可以在这些类型之间转换

C# 从类型';System.String';输入'';Y';失败,因为没有类型转换器可以在这些类型之间转换,c#,.net,asp.net-mvc-4,C#,.net,Asp.net Mvc 4,我被这个错误绊住了,我检查了值是否为空。当我试图按下保存按钮时,出现了这个错误 请帮助我,这是错误: The parameter conversion from type 'System.String' to type 'ULIV.ViewModels.NewProposal' failed because no type converter can convert between these types. ModelState.IsValid为false 以下是使用的视图模型: public

我被这个错误绊住了,我检查了值是否为空。当我试图按下保存按钮时,出现了这个错误

请帮助我,这是错误:

The parameter conversion from type 'System.String' to type 'ULIV.ViewModels.NewProposal' failed because no type converter can convert between these types.
ModelState.IsValid为false

以下是使用的视图模型:

public class PurchaseOrderViewModel
{
    [Key]
    public int ID { get; set; }

    public IEnumerable<Institution> Institution { get; set; }

    [Required]
    public string PurchaseOrderNo { get; set; }

    [Required]
    public DateTime PurchaseOrderDate { get; set; }

    [Required]
    public DateTime ReceivedDate { get; set; }

    public string Remarks { get; set; }

    public IEnumerable<NewProposal> Proposal { get; set; }


    public IEnumerable<PODetail> PODetail { get; set; }

    public IEnumerable<NewProposal> AddedProposal { get; set; }


}
公共类PurchaseOrderViewModel
{
[关键]
公共int ID{get;set;}
公共IEnumerable机构{get;set;}
[必需]
公共字符串PurchaseOrderNo{get;set;}
[必需]
公共日期时间PurchaseOrderDate{get;set;}
[必需]
公共日期时间接收日期{get;set;}
公共字符串备注{get;set;}
公共IEnumerable建议{get;set;}
公共IEnumerable PODetail{get;set;}
公共IEnumerable AddedProposal{get;set;}
}
这是控制器操作:

[HttpPost]
    public ActionResult Create(PurchaseOrderViewModel purchaseorderviewmodel)
    {

        purchaseorderviewmodel.AddedProposal  = (List<ULIV.ViewModels.NewProposal>)Session["AddedProposal"];



        //purchaseorderviewmodel.Proposal = db.NewProposal.Where(x => x.Status.StatusID == 3).ToList();



        int instituionId = Convert.ToInt32(Session["InstitutionID"]);

        purchaseorderviewmodel.Institution = db.Institutions.Where(x => x.InstitutionID == instituionId).ToList();

        if (ModelState.IsValid)
        {
            db.PurchaseOrderViewModels.Add(purchaseorderviewmodel);
            db.SaveChanges();
            return RedirectToAction("Index","Fulfillment");
        }


        ViewBag.Proposal = new SelectList(db.NewProposal.Where(x => x.Status.StatusID == 3), "ProposalID", "ProposalCode");
        return View(purchaseorderviewmodel);
    }
[HttpPost]
公共操作结果创建(PurchaseOrderViewModel PurchaseOrderViewModel)
{
purchaseorderviewmodel.AddedProposal=(列表)会话[“AddedProposal”];
//purchaseorderviewmodel.Proposal=db.NewProposal.Where(x=>x.Status.StatusID==3.ToList();
int InstitutionID=Convert.ToInt32(会话[“InstitutionID]”);
purchaseorderviewmodel.Institution=db.Institutions.Where(x=>x.InstitutionID==InstitutionID.ToList();
if(ModelState.IsValid)
{
db.PurchaseOrderViewModels.Add(purchaseorderviewmodel);
db.SaveChanges();
返回重定向操作(“索引”、“履行”);
}
ViewBag.Proposal=new SelectList(db.NewProposal.Where(x=>x.Status.StatusID==3),“ProposalID”,“ProposalCode”);
返回视图(purchaseorderviewmodel);
}
此外,以下是即时窗口上的值:

((List<ULIV.ViewModels.NewProposal>)Session["AddedProposal"]).FirstOrDefault()

DateModified: {1/15/2014 2:57:52 PM}
FinalUnitPrice: 23
FinalVolume: 34
getdatestring: "1/15/2014"
Institution: {System.Data.Entity.DynamicProxies.Institution_B01649AB79941CE0188D081B425698F4FD6629E82FDB13CCE17B03E348459273}
InstitutionID: 1
Product: {ULIV.Models.ProductModel}
ProductID: 1
ProposalCode: "PC-2014-00001"
ProposalID: 1
ProposedUnitPrice: 3
ProposedVolume: "2"
RelatedProposalCode: ""
Remarks: "hello"
Status: {ULIV.Models.Status}
StatusID: 3
VaccineType: {ULIV.Models.VaccineType}
VaccineTypeID: 1
((List<ULIV.ViewModels.NewProposal>)Session["AddedProposal"]).FirstOrDefault()
((列表)会话[“AddedProposal]”)。FirstOrDefault()
修改日期:{1/15/2014 2:57:52 PM}
最终价格:23
最终体积:34
getdatestring:“1/15/2014”
机构:{System.Data.Entity.DynamicProxies.Institution_B01649AB79941CE0188D081B425698F4FD6629E82FDB13CCE17B03E348459273}
机构编号:1
产品:{ULIV.Models.ProductModel}
产品编号:1
提议代码:“PC-2014-00001”
提案人:1
建议单价:3
建议卷:“2”
相关提议代码:“
备注:“你好”
状态:{ULIV.Models.Status}
身份证号码:3
疫苗类型:{ULIV.Models.VaccineType}
疫苗种类:1
((列表)会话[“AddedProposal]”)。FirstOrDefault()
这是一种观点:

<div class="row">
@using (Html.BeginForm("Create", "PurchaseOrder",
        new { ReturnUrl = ViewBag.ReturnUrl },
        FormMethod.Post, new { @class = "form-horizontal" }))
{
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)

    <h1 class="subpage-headline font-global">New Purchase Order</h1>
    <div class="row">
        <h2 class="subpage-headline2 font-global">New Purchase Order</h2>
        @*<form class="form-horizontal" role="form">*@
            @foreach (var inst in Model.Institution)
            {
                <div class="row-div">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">Institution Name:</label>
                        <div class="col-sm-3">
                            <label class="control-text-label">@Html.DisplayFor(modelItem => inst.InstitutionName)</label>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">Account Classifications:</label>
                        <div class="col-sm-3">
                            <label class="control-text-label">Private</label>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">Employee Population:</label>
                        <div class="col-sm-3">
                            <label class="control-text-label">50</label>
                        </div>
                    </div>
                </div>
                <div class="row-div">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">Address:</label>
                        <div class="col-sm-4">
                            <label class="control-text-label">Ninoy Aquino Ave. Clark Pampanga Clark Freeport Zone 1500</label>
                        </div>

                    </div>

                    <div class="form-group">

                        <label class="col-sm-2 control-label">Telephone No.:</label>
                        <div class="col-sm-3">
                            <label class="control-text-label">599-3146</label>
                        </div>
                    </div>
                </div>
            }
        @*</form>*@
        @*<form class="form-horizontal" role="form">*@
            <div class="form-group">
                <label class="col-sm-2 control-label">Purchase Order Number:</label>
                <div class="col-sm-4">

                    @Html.TextBoxFor(model => model.PurchaseOrderNo, new { @class = "form-control", @type = "text" })
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">Purchse Order Date:</label>
                <div class="col-sm-4">
                    @Html.TextBoxFor(model => model.PurchaseOrderDate, new { @class = "form-control datepicker", @type = "text" })
                </div>
            </div>
            <div class="row">
                <label class="col-sm-2"></label>
                <label class="col-sm-2 font-md">Proposal Code <span class="required">*</span></label>
                <label class="col-sm-2 font-md">Description <span class="required">*</span></label>
                <label class="col-sm-2 font-md">Unit Price w/ VAT <span class="required">*</span></label>
                <label class="col-sm-1 font-md">Total Units <span class="required">*</span></label>
                <label class="col-sm-2 font-md">Total Amount w/ VAT <span class="required">*</span></label>
                <label class="col-sm-1"></label>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">Proposal:</label>
                <div class="col-sm-2">


                    @Html.DropDownList("ProposalID", new SelectList(ViewBag.Proposal, "Value", "Text"), "SELECT Proposal", new { @class = "form-control input", @type = "text", @name = "ddlInst" })


                </div>


                    <div class="col-sm-2">
                        <input type="text" class="form-control" id="prodDesc_0">
                    </div>
                    <div class="col-sm-2">
                        <input type="text" class="form-control" id="unitPrice_0">
                    </div>
                    <div class="col-sm-1">
                        <input type="text" class="form-control" id="totalUnits_0">
                    </div>
                    <div class="col-sm-2">
                        <input type="text" class="form-control" id="totalAmount_0">
                    </div>
                    <div class="col-sm-1">
                        <button type="button" class="btn btn-primary" onclick="AddProposal()">Add</button>
                    </div> 

            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">Product:</label>
                <div class="col-sm-9">
                    <table class="table table-bordered table-hover">
                        <thead>
                            <tr class="th-center">
                                <th>Proposal Code</th>
                                <th>Description</th>
                                <th>Unit Price VAT</th>
                                <th>Total Units</th>
                                <th>Total Amount w/ VAT</th>
                                <th>Action</th>
                            </tr>
                        </thead>

                        <tbody>
                            @Html.HiddenFor(model => model.AddedProposal)
                            @if (Model.AddedProposal != null)
                            {
                                foreach (var prop in Model.AddedProposal)
                                {
                                <tr class="text-center">
                                    <td>@Html.DisplayFor(modelItem => prop.ProposalCode)</td>
                                    <td>@Html.DisplayFor(modelItem => prop.Product.Description)</td>
                                    <td>@Html.DisplayFor(modelItem => prop.FinalUnitPrice)</td>
                                    <td>@Html.DisplayFor(modelItem => prop.FinalVolume)</td>
                                    <td>3875.75</td>
                                    <td class="text-center">
                                        <a href="#">
                                            <img src="../../Images/icon_delete.png" width="16" height="16"></a>
                                    </td>
                                </tr>
                                }
                            }
                            @if (Model.AddedProposal == null)
                            {
                            }
                        </tbody>
                    </table>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">Received Date:</label>
                <div class="col-sm-4">
                    @Html.TextBoxFor(model => model.ReceivedDate, new { @class = "form-control datepicker", @type = "text" })
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">Remarks:</label>
                <div class="col-sm-4">
                    @Html.TextBoxFor(model => model.Remarks, new { @class = "form-control", @type = "text" })
                </div>
            </div>
        @*</form>*@
    </div>
    <div class="row col-xs-offset-2" style="padding-top: 30px;">
        <button type="submit" class="btn btn-primary">Save</button>
        <button type="button" class="btn btn-primary" onclick="window.location='@Url.Action("Index", "Fulfillment")'">Cancel</button>
    </div>
}

@使用(Html.BeginForm(“创建”、“采购订单”),
新建{ReturnUrl=ViewBag.ReturnUrl},
FormMethod.Post,新的{@class=“form horizontal”})
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
新采购订单
新采购订单
@**@
@foreach(模型机构中的var inst)
{
机构名称:
@DisplayFor(modelItem=>inst.InstitutionName)
账户分类:
私有的
雇员人数:
50
地址:
克拉克潘潘帕加克拉克自由港区尼诺阿基诺大道1500号
电话号码:
599-3146
}
@**@
@**@
采购订单编号:
@Html.TextBoxFor(model=>model.PurchaseOrderNo,新的{@class=“form control”,@type=“text”})
购买订单日期:
@Html.TextBoxFor(model=>model.PurchaseOrderDate,新的{@class=“form control datepicker”,@type=“text”})
提案代码*
描述*
含增值税的单价*
总单位*
总金额(含增值税)*
提议:
@DropDownList(“ProposalID”、新的选择列表(ViewBag.Proposal、“Value”、“Text”)、“SELECT Proposal”、新的{@class=“form control input”、@type=“Text”、@name=“ddlInst”})
添加
产品:
提案代码
描述
单价增值税
总单位
总金额(含增值税)
行动
@Html.HiddenFor(model=>model.AddedProposal)
@if(Model.AddedProposal!=null)
{
foreach(模型中的var prop.AddedProposal)
{
@Html.HiddenFor(model => model.AddedProposal)
Html.DropDownListFor(m => m.SiteExtendedAttributeValues[0] etc.
Html.DropDownListFor(m => m.SiteExtendedAttributeValues[0].SiteExtendedAttributeDefinitionId
public async Task<ActionResult> Add(string m = null) { }

[HttpPost]
public async Task<ActionResult> Add(FooViewModel m) { }