'System.Collections.Generic.List <x> .Add的最佳重载方法匹配有一些无效的参数

时间:2016-02-29 16:31:28

标签: c# asp.net-mvc

我查看了堆栈溢出的档案,但无法得到我所得错误的答案。

整个错误是

Error   283 The best overloaded method match for 'System.Collections.Generic.List<ds_iDMS.Models.Person.SearchReturnListItem>.Add(ds_iDMS.Models.Person.SearchReturnListItem)' has some invalid arguments   C:\Users\mgay.AUTOSQL\Source\Workspaces\ds_iDMS\webSites\ds_iDMS\Controllers\CustomerController.cs  242 25  ds_iDMS

位于控制器中的此代码中

        [System.Web.Mvc.HttpGet]
    public ActionResult _PersonSearch(SearchViewModel vm)
    {
        //var service = new CustomerService(mobjSecurity);

        //var svm = service.FetchSearchViewModel();

        //return PartialView(svm);
        var personManager = new dtPerson_v10_r1.Manager(ref mobjSecurity);
        var vmReturn = new SearchReturnListViewModel();


        vmReturn.AllowAdd = vm.AllowAdd;
        vmReturn.AllowUpdate = vm.AllowUpdate;
        vmReturn.AddReference = vm.AddReference;
        vmReturn.EditReference = vm.EditReference;
        vmReturn.CallBackFunction = vm.CallBack;

        var ssn = mobjFormat.StripSocialSecurityToString(vm.Identity.SSN);
        var lName = mobjFormat.StripObjectToString(vm.Identity.LName);
        var fName = mobjFormat.StripObjectToString(vm.Identity.FName);
        var mName = mobjFormat.StripObjectToString(vm.Identity.MName);
        var suffix = mobjFormat.StripObjectToString(vm.Identity.Suffix);
        var personId = mobjFormat.StripObjectToInt32(vm.Identity.PersonId);
        var gender = mobjFormat.StripObjectToString(vm.Identity.Gender);
        var dob = mobjFormat.FormatShortDateString(vm.Identity.DOB);
        var salutation = mobjFormat.StripObjectToString(vm.Identity.Salutation);

        if (ssn == "" && lName == "" && fName == "" && mName == "" && suffix == "" && personId == 0)
        {

        }
        else
        {
            vmReturn.Identity.PersonId = personId;
            vmReturn.Identity.SSN = ssn;
            vmReturn.Identity.FName = fName;
            vmReturn.Identity.MName = mName;
            vmReturn.Identity.LName = lName;
            vmReturn.Identity.Suffix = suffix;
            vmReturn.Identity.Gender = gender;
            vmReturn.Identity.Salutation = salutation;
            vmReturn.Identity.DOB = dob;

            var dsReturn = personManager.GetPersonList(ssn, lName, fName, mName, suffix, personId);

            if (dsReturn.Tables.Count > 0)
            {
                foreach (DataRow row in dsReturn.Tables[1].Rows)
                {
                    //var item = new SearchReturnListItem();
                    var item = new SearchViewModel();

                    item.Identity.PersonId = mobjFormat.StripObjectToInt32(row["Person_ID"]);
                    item.Identity.SSN = mobjFormat.StripObjectToString(row["ssn"]);
                    item.Identity.FName = mobjFormat.StripObjectToString(row["FName"]);
                    item.Identity.MName = mobjFormat.StripObjectToString(row["MName"]);
                    item.Identity.LName = mobjFormat.StripObjectToString(row["LName"]);
                    item.Identity.Suffix = mobjFormat.StripObjectToString(row["Suffix"]);
                    item.Identity.DOB = mobjFormat.FormatShortDateString(row["dob"]);
                    //address
                    item.SearchItem.CurrentAddress.Address.Add1 = mobjFormat.StripObjectToString(row["Add1"]);
                    item.SearchItem.CurrentAddress.Address.Add2 = mobjFormat.StripObjectToString(row["Add2"]);
                    item.SearchItem.CurrentAddress.Address.City = mobjFormat.StripObjectToString(row["City"]);
                    item.SearchItem.CurrentAddress.Address.County = mobjFormat.StripObjectToString(row["County"]);
                    item.SearchItem.CurrentAddress.Address.State = mobjFormat.StripObjectToString(row["State"]);
                    item.SearchItem.CurrentAddress.Address.Zip = mobjFormat.StripObjectToString(row["Zip"]);
                    item.SearchItem.CurrentAddress.Address.Country = mobjFormat.StripObjectToString(row["Country"]);

                    if (personId != 0 && personId == item.Identity.PersonId)
                    {
                        vmReturn.HasIdMatch = true;
                        //item.IsIdMatch = true;
                        item.SearchItem.IsIdMatch = true;
                    }

                    if (ssn != "" && ssn == item.Identity.SSN)
                    {
                        vmReturn.HasSSNMatch = true;
                        //item.IsSSNMatch = true;
                        item.SearchItem.IsSSNMatch = true;
                    }

                    var isFNameMatch = false;
                    var isMNameMatch = false;
                    var isLNameMatch = false;
                    var isSuffixMatch = false;
                    var mNameTested = false;
                    var suffixTested = false;

                    if (fName == item.Identity.FName)
                    {
                        isFNameMatch = true;
                    }

                    if (lName == item.Identity.LName)
                    {
                        isLNameMatch = true;
                    }

                    if (mName == item.Identity.MName)
                    {
                        isMNameMatch = true;
                    }
                    else
                    {
                        if (mName == "" || item.Identity.MName == "")
                        {
                            mNameTested = false;
                            isMNameMatch = true;
                        }
                        else
                        {
                            mNameTested = true;
                            isMNameMatch = true;
                        }
                    }

                    if (suffix == item.Identity.Suffix)
                    {
                        suffixTested = true;
                        isSuffixMatch = true;
                    }
                    else
                    {
                        if (suffix == "" || item.Identity.Suffix == "")
                        {
                            suffixTested = false;
                            isSuffixMatch = true;
                        }
                        else
                        {
                            suffixTested = true;
                            isSuffixMatch = true;
                        }
                    }

                    if (isFNameMatch && isLNameMatch && isMNameMatch && isSuffixMatch)
                    {
                        if (mNameTested && suffixTested)
                        {
                            vmReturn.HasFullNameMatch = true;
                            //item.IsFullNameMatch = true;
                            item.SearchItem.IsFullNameMatch = true;
                        }
                        else
                        {
                            vmReturn.HasPartialNameMatch = true;
                            //item.IsPartialNameMatch = true;
                            item.SearchItem.IsPartialNameMatch = true;
                        }
                    }

                    //Add this to the list
                    vmReturn.Identities.Add(item);  //error line *****//


                }
            }
        }

这是它正在使用的模型

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace ds_iDMS.Models.Person
{

     public enum PersonViews { Main, Lookup, Customer, Deals,         Accounts, Transactions, Debts, Assets, References, Files, CreditBureau, CreditReporting, Notes, eCabinet };

public class PersonMainViewModel
{
    public PersonViews CurrentView = PersonViews.Main;
    public int PersonId { get; set; }
}


public class IdentityViewModel
{
    public int CreateNew { get; set; }
    public bool isInitialized;
    public IdentityViewModel()
    {
        CreateNew = 0;
        //Construct List
        SalutationList = new List<SelectListItem>();
        SuffixList = new List<SelectListItem>();
        GenderList = new List<SelectListItem>();
        isInitialized = true;
    }

    //common list
    public List<SelectListItem> SalutationList { get; set; }
    public List<SelectListItem> SuffixList { get; set; }
    public List<SelectListItem> GenderList { get; set; }

    //Identity
    public int? PersonId { get; set; }

    //For View Only
    public string FullName { get; set; }

    [Display(Name = @"SSN")]
    [DataType("ssn")]
    public string SSN { get; set; }

    [Display(Name = @"Salutation")]
    public string Salutation { get; set; }

    [Display(Name = @"Last Name")]
    public string LName { get; set; }

    [Display(Name = @"First Name")]
    public string FName { get; set; }

    [Display(Name = @"Middle Name")]
    public string MName { get; set; }

    [Display(Name = @"Suffix")]
    public string Suffix { get; set; }

    [Display(Name = @"Gender")]
    public string Gender { get; set; }

    [DataType("date")]
    [Display(Name = @"Date Of Birth")]
    public string DOB { get; set; }

    //Reference
    public int ReferenceTypeID { get; set; }
    public bool AddReference { get; set; }

}

public class SearchViewModel
{
    public bool HasError { get; set; }   //********//
    public dtPerson_v10_r1.Person personObject { get; set; }
    public bool AllowAdd { get; set; }
    public bool AllowUpdate { get; set; }
    public string CallBack { get; set; }
    public IdentityViewModel Identity { get; set; }
    public bool AddReference { get; set; }
    public bool EditReference { get; set; }
    public int? OrderNumber { get; set; }
    public int? Deal_ID { get; set; }
    public List<SelectListItem> ReferenceTypes { get; set; }
    public SearchReturnListViewModel SearchReturn { get; set; }
    public SearchReturnListItem SearchItem { get; set; }

    [Display(Name = @"Relationship")]
    public int PopReferenceTypeID { get; set; }

    public SearchViewModel()
    {
        //Construct Properties
        Identity = new IdentityViewModel();
        ReferenceTypes = new List<SelectListItem>();
        SearchReturn = new SearchReturnListViewModel();
        SearchItem = new SearchReturnListItem();
    }

}

public class SearchReturnListViewModel
{
    public string CallBackFunction { get; set; }
    public bool AllowAdd { get; set; }
    public bool AllowUpdate { get; set; }
    public int? CurPersonId { get; set; }  //may not need
    public bool HasIdMatch { get; set; }
    public bool HasSSNMatch { get; set; }
    public bool HasFullNameMatch { get; set; }  //FName MName LName Suffix
    public bool HasPartialNameMatch { get; set; }  //FName MName LName Suffix
    public bool AddReference { get; set; }
    public int ReferenceTypeID { get; set; }
    public IdentityViewModel Identity { get; set; }
    public List<SearchReturnListItem> Identities { get; set; }
    //public List<IdentityListItem> Identities { get; set; }
    public bool EditReference { get; set; }

    public SearchReturnListViewModel()
    {
        //Construct properties
        Identity = new IdentityViewModel();
        Identities = new List<SearchReturnListItem>();
    }
}

public class IdentityListItem
{
    public bool isInitialized;
    public IdentityListItem()
    {
        //Construct Property
        CurrentAddress = new AddressViewModel();
        CurrentAddress.Address = new BaseAddressViewModel();
    }

    public int? PersonId { get; set; }
    public bool SSNMatch { get; set; }
    public bool NameMatch { get; set; }
    public bool IdMatch { get; set; }
    public string SSN { get; set; }
    public string FName { get; set; }
    public string MName { get; set; }
    public string LName { get; set; }
    public string Suffix { get; set; }
    public string DOB { get; set; }

    //Address
    [Display(Name = @"Current")]
    public AddressViewModel CurrentAddress { get; set; }
}

public class PersonViewModel
{
    public bool isInitialized;
    public PersonViewModel()
    {
        //Construct List
        StateList = new List<SelectListItem>();
        CountryList = new List<SelectListItem>();
        ResTypeList = new List<SelectListItem>();
        EmploymentTypeList = new List<SelectListItem>();
        RefTypeList = new List<SelectListItem>();
        SalutationList = new List<SelectListItem>();
        SuffixList = new List<SelectListItem>();
        GenderList = new List<SelectListItem>();
        AssetTypeList = new List<SelectListItem>();
        DebtTypeList = new List<SelectListItem>();

        //Construct Properties
        CurrentAddress = new AddressViewModel();
        CurrentAddress.Address = new BaseAddressViewModel();
        PreviousAddress = new BaseAddressViewModel();
        PreviousAddress.Address = new BaseAddressViewModel();
        CurrentEmployment = new PersonEmploymentItem();
        CurrentEmployment.Address = new BaseAddressViewModel();
        PreviousEmployment = new PersonEmploymentItem();
        //PreviousEmployment.Address = new BaseAddressViewModel();
        PreviousEmployment.Address = new BaseAddressViewModel();

        Debt1 = new PersonDebtItem();
        Debt2 = new PersonDebtItem();
        Debt3 = new PersonDebtItem();

        Asset1 = new PersonAssetItem();
        Asset2 = new PersonAssetItem();
        Asset3 = new PersonAssetItem();

        isInitialized = true;
    }

    //Common List
    public List<SelectListItem> StateList { get; set; }
    public List<SelectListItem> CountryList { get; set; }
    public List<SelectListItem> ResTypeList { get; set; }
    public List<SelectListItem> EmploymentTypeList { get; set; }
    public List<SelectListItem> RefTypeList { get; set; }
    public List<SelectListItem> SalutationList { get; set; }
    public List<SelectListItem> SuffixList { get; set; }
    public List<SelectListItem> GenderList { get; set; }
    public List<SelectListItem> AssetTypeList { get; set; }
    public List<SelectListItem> DebtTypeList { get; set; }

    //Identity
    [Display(Name = @"SSN")]
    [DataType("ssn")]
    public string SSN { get; set; }

    [Display(Name = @"Salutation")]
    public string Salutation { get; set; }

    [Display(Name = @"Last Name")]
    public string LName { get; set; }

    [Display(Name = @"First Name")]
    public string FName { get; set; }

    [Display(Name = @"Middle Name")]
    public string MName { get; set; }

    [Display(Name = @"Suffix")]
    public string Suffix { get; set; }

    [Display(Name = @"Gender")]
    public string Gender { get; set; }

    [Display(Name = @"DL Number")]
    public string DlNumber { get; set; }

    [Display(Name = @"DL State")]
    public string DlState { get; set; }

    [Display(Name = @"DL Exp Date")]
    public string DlExpire { get; set; }

    [DataType("date")]
    [Display(Name = @"Date Of Birth")]
    public string DOB { get; set; }

    //Contact Information 
    [DataType("email")]
    [Display(Name = @"Email")]
    public string Email { get; set; }

    [DataType("phone")]
    [Display(Name = @"Home Phone")]
    public string HPhone1 { get; set; }

    [DataType("phone")]
    [Display(Name = @"Home Phone 2")]
    public string HPhone2 { get; set; }

    [DataType("phone")]
    [Display(Name = @"Work Phone")]
    public string BPhone1 { get; set; }

    [Display(Name = @"Work Extension")]
    public string BExtension1 { get; set; }

    [DataType("phone")]
    [Display(Name = @"Work Phone 2")]
    public string BPhone2 { get; set; }

    [Display(Name = @"Work Extension 2")]
    public string BExtension2 { get; set; }

    [DataType("phone")]
    [Display(Name = @"Cell Phone")]
    public string CPhone { get; set; }

    [DataType("phone")]
    [Display(Name = @"Pager")]
    public string Pager { get; set; }

    [DataType("phone")]
    [Display(Name = @"Fax 1")]
    public string Fax1 { get; set; }

    [DataType("phone")]
    [Display(Name = @"Fax 2")]
    public string Fax2 { get; set; }

    [DataType("phone")]
    [Display(Name = @"Other Phone")]
    public string Other1 { get; set; }

    //Address
    [Display(Name = @"Current")]
    public AddressViewModel CurrentAddress { get; set; }

    [Display(Name = @"Previous")]
    public BaseAddressViewModel PreviousAddress { get; set; }

    //Employment
    public PersonEmploymentItem CurrentEmployment { get; set; }
    public PersonEmploymentItem PreviousEmployment { get; set; }

    //Debts
    public PersonDebtItem Debt1 { get; set; }
    public PersonDebtItem Debt2 { get; set; }
    public PersonDebtItem Debt3 { get; set; }

    //Assets
    public PersonAssetItem Asset1 { get; set; }
    public PersonAssetItem Asset2 { get; set; }
    public PersonAssetItem Asset3 { get; set; }
}

public class BaseAddressViewModel         
{
    [Display(Name = @"Address 1")]
    public string Add1 { get; set; }

    [Display(Name = @"Address 2")]
    public string Add2 { get; set; }

    public string City { get; set; }

    public string County { get; set; }

    public string State { get; set; }

    [DataType("zipcode")]
    public string Zip { get; set; }

    public string Country { get; set; }

    [DataType("numeric")]
    [Display(Name = @"Months At")]
    public int? TimeAt_Months { get; set; }

    [DataType("numeric")]
    [Display(Name = @"Years At")]
    public int? TimeAt_Years { get; set; }

    public BaseAddressViewModel Address { get; set; }
}

public class PersonEmploymentItem
{
    [Display(Name = @"Employment Type")]
    public string EmploymentType { get; set; }

    [Display(Name = @"Employer")]
    public string Employer { get; set; }

    [Display(Name = @"Position")]
    public string EmployerPosition { get; set; }

    public BaseAddressViewModel Address { get; set; }
}

public class AddressViewModel     
{
    [Display(Name = @"Residence Type")]
    public string ResType { get; set; }

    [Display(Name = @"Residence Payment")]
    [DataType("currency")]
    public decimal? ResPayment { get; set; }

    [Display(Name = @"Lien Holder")]
    public string ResLienHolder { get; set; }

    [DataType("phone")]
    [Display(Name = @"Lien Holder Phone")]
    public string ResLienHolderPhone { get; set; }

    public BaseAddressViewModel Address { get; set; }

    public AddressViewModel()
    {
        Address = new BaseAddressViewModel();
    }
}

public class PersonAssetItem
{
    [Display(Name = @"Asset Type")]
    public int? AssetType_ID { get; set; }

    [Display(Name = @"Asset Desc")]
    public string AssetDesc { get; set; }

    [DataType("currency")]
    [Display(Name = @"Asset Value")]
    public decimal? AssetValue { get; set; }
}

public class PersonDebtItem
{
    [Display(Name = @"Debt Type")]
    public int? DebtType_ID { get; set; }

    [Display(Name = @"Creditor")]
    public string Creditor { get; set; }

    [Display(Name = @"Account Number")]
    public string AcctNumber { get; set; }

    [DataType("currency")]
    [Display(Name = @"Payment")]
    public decimal? MonthlyPayment { get; set; }

    [DataType("currency")]
    [Display(Name = @"Original Balance")]
    public int? OrigBalance { get; set; }

    [DataType("currency")]
    [Display(Name = @"Current Balance")]
    public int? CurBalance { get; set; }
}

public class SearchReturnListItem
{
    public bool isInitialized;

    //Identity
    public IdentityViewModel Identity { get; set; }

    //Address
    public AddressViewModel CurrentAddress { get; set; }

    public bool IsSSNMatch { get; set; }
    public bool IsFullNameMatch { get; set; }
    public bool IsPartialNameMatch { get; set; }
    public bool IsIdMatch { get; set; }

    public SearchReturnListItem()
    {
        //Construct properties
        Identity = new IdentityViewModel();
        CurrentAddress = new AddressViewModel();
    }
}

}

我附上整个模型,因为我想确保尽可能多地为您提供信息。

我试图将错误行切换到

vm.Identities.AddRange(item)

无济于事我也试过

vm.Identities.AddRange[item]

也无法解决错误。以前有人有这个问题吗?我不完全确定如何解决这个问题,但如果你能指出我正确的方向,我会很感激

1 个答案:

答案 0 :(得分:0)

itemSearchViewModel

var item = new SearchViewModel();

vmReturn.IdentitiesList<ds_iDMS.Models.Person.SearchReturnListItem>

public List<SearchReturnListItem> Identities { get; set; }

因此,您要么将错误的项目添加到列表中,要么将该项目添加到错误的列表中。

使用代码墙很难知道哪个是正确的或要修改什么来修复它。我建议将代码重构为更小的方法 - 这可以帮助您确定问题所在。