0

I am new to asp.net MVC-4 and stuck up while retrieving data from view to controller in case of render single partial view twice on company/create.cshtml

My complex model is as follow.

public partial class Company
{
    public int CCode { get; set; }
    public string CName { get; set; }
    public string Addr1 { get; set; }
    public string Addr2 { get; set; }
    public string City { get; set; }
    public string Country { get; set; }
    public string EmailID { get; set; }
    public string Remarks { get; set; }


    public CompanyContacts Contacts { get; set; }
    public partial class CompanyContacts
    {
        public int refCCode_Company { get; set; }
        public int SrNo { get; set; }
        public string ContactPerson { get; set; }
        public string Designation { get; set; }
        public string Contact1 { get; set; }
        public string Contact2 { get; set; }
        public string EmailID { get; set; }
        public string IsActive { get; set; }
    }
}

where in the CompanyContact is partial view rendered twice in company/create.cshtml page.

"@model ProjectName.Models.Company" so that i can bind HTML control as follow. @HTML.TextBoxFor(model >= model.CompanyContact)

<div class="tab-pane fade" id="contacts">
      <div class="col-md-6">
             <p>
                   @Html.Partial("_LedgerContactsPartial")
             </p>
      </div>
      <div class="col-md-6">
             <p>
                   @Html.Partial("_LedgerContactsPartial")
             </p>
      </div>
</div>

while save the data, how do i pass two contact person details to controller.

Thanks in Adv.

Hi Ten
  • 93
  • 2
  • 16

1 Answers1

1

You need to pass list of contact person details to controller. to achieve this you could follow naming convention for input fields that the default ModelBinder expects to bind to a list.

This article by Phill Hack shows Model Binding To A List.

And take look to this question How to pass IEnumerable list to controller in MVC including checkbox state.

Community
  • 1
  • 1
Mohsen Esmailpour
  • 11,224
  • 3
  • 45
  • 66