2016-02-29 79 views
-1

我已經瀏覽了堆棧溢出的檔案,並且無法獲得我得到的錯誤的答案。對'System.Collections.Generic.List <X> .Add <X> .Add的最佳重載方法匹配有一些無效的參數

整個誤差是

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(); 
    } 
} 

}

模型

我atta因爲我想確保我有儘可能多的信息給你,

我試圖錯誤行切換到

vm.Identities.AddRange(item) 

無濟於事我還試圖

vm.Identities.AddRange[item] 

另外要沒有解決的錯誤。有沒有人有過這個問題?我不完全知道如何解決這個問題,但如果你能在正確的方向指向我,我將不勝感激

+5

您已經在這裏發佈了*很大數量的代碼(600行!)。請把它縮小到[mcve]。 –

+0

您正試圖將SearchViewModel對象添加到僅接受SearchReturnListItem類型的對象的列表中。定義你的var項目的註釋掉的代碼看起來是正確的。或者身份列表未正確定義。非此即彼。 – ManoDestra

+0

@ManoDestra - 謝謝你解決了錯誤 – MaximusPrime

回答

0

itemSearchViewModel

var item = new SearchViewModel(); 

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

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

因此,您要麼將錯誤的項目添加到列表中,要麼將項目添加到錯誤的列表中。

隨着代碼的牆壁,很難知道哪個是正確的或要修改的是什麼。我建議將代碼重構爲更小的方法 - 這可以幫助您確定問題所在。

+0

謝謝我知道這是很多代碼,我不知道如何解決它。只要我能夠,我會標記這個答案 – MaximusPrime

相關問題