2016-04-11 22 views
0

Bir ASP.NET MVC projesinde çalışıyorum ve formumda bir DropDown listesi özel uygulamasına sahibim. Bir hesap seçiyorum ve bu hesaba göre hesap altında yapılan kişileri seçebilmek istiyorum. İşte Özel DropDownFor yükleme Varlığa göre değer

burada

public static MvcHtmlString AccountContactsDropdownFor<TModel, TEnum>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TEnum>> expression, Guid parentId, object htmlAttributes = null) 
    { 
     QueryRequestHelper<AccountContacts, FMRequestDispatcher> request = new QueryRequestHelper<AccountContacts, FMRequestDispatcher>(); 
     EntityReference reference = new EntityReference() { EntityName = "Account", Id = parentId }; 
     int count = 0; 
     IEnumerable query = request.Query(string.Empty, string.Empty, 0, 100, out count, reference); 

     List<SelectListItem> items = new List<SelectListItem>(); 
     foreach (Contact contacts in query) 
     { 
      SelectListItem li = new SelectListItem(); 
      li.Value = contacts.Id.ToString(); 
      li.Text = contacts.FirstName[0] + ". " + contacts.LastName; 
      items.Add(li); 
     } 

     return SelectExtensions.DropDownListFor(htmlHelper, expression, items, htmlAttributes); 
    } 

Ve aşağıda benim kod bunun kod

   <li> 
        @Html.Label(Localization_Financial.Account) <br> 
        @Html.AccountNameDropdownFor(m => m.AccountId) 
       </li> 
       <li> 
        @Html.Label(Localization_Financial.Contact) <br> 
        @Html.AccountContactsDropdownFor(m => m.ContactId, Model.AccountId) 
       </li> 

Yani dropdownfor bir hesap seçiyorum zaman benim şeklidir (İletişim model accountid vardır) Yukarıda uygulamamın yeniden yüklenmesini veya bir şeyler yapmasını istiyorum. Bu nedenle, hesabıma ait kişilerle birlikte seçili kutuyu günceller.

Bunu yapmanın etkili bir yolu var mı?

cevap

0

Bir süre sonra cevabı kendim buldum.

Bunu yapmak benim kodum.

 myFunction(); 
    $("#AccountId").change(myFunction); 
}) 

function myFunction() { 
    $.getJSON("/Crm/Invoice/JsonContacts", { AccountId: $("#AccountId").val() }, 
     function (result) { 
      var ddl = $('#ContactId'); 
      ddl.empty(); 
      var count = "0"; 

      $(result).each(function() { 
       count = 1; 
       ddl.append(
        $('<option/>', { 
         value: this.Id 
        }).html(this.FirstName[0] + ". " + this.LastName) 
       ); 
      }); 
} 
İlgili konular