1

取得した値を ListBoxFor に入力する方法を教えてください。私はこれを試しましたが、うまくいきません。

モデルのコード:-

public List<SelectListItem> SafetyRepresentataives { get; set; }
public List<string> BusinessUnitSiteSafetyRepresentative { get; set; }

コントローラー内のコード:=

var site = entityDB.ClientBusinessUnitSites.FirstOrDefault(m => m.ClientBusinessUnitSiteId == 
siteId);
var siteRepresentatives = from representatives in entityDB.ClientBusinessUnitSiteRepresentatives
                                      where representatives.ClientBUSiteID == siteId
                                      select representatives;

local.SafetyRepresentataives = (from o in entityDB.SystemUsersOrganizations.ToList()
                                           from c in entityDB.Contact.ToList()
                                           where o.OrganizationId == clientId && c.UserId == 
                                            o.UserId
                                           select new SelectListItem
                                           {
                                               Text = c.FirstName + "," + c.LastName,
                                               Value = c.UserId.ToString()
                                           }).ToList();
foreach (var representative in siteRepresentatives)
            {   
local.BusinessUnitSiteSafetyRepresentative.Add(representative.SafetyRepresentative.ToString());
            }

ビュー内のコード:-

@Html.ListBoxFor(x => Model.BusinessUnitSiteSafetyRepresentative, new 
MultiSelectList(Model.SafetyRepresentataives,"Value","Text"))

上記のようにDBから値を取得しました。しかし、取得したこれらの値を ListBox にリンクして入力することはできません。これを行う方法??助けてください!!!!!!!!

4

2 に答える 2

0

I think this link should help you

http://www.asp.net/mvc/tutorials/javascript/working-with-the-dropdownlist-box-and-jquery/using-the-dropdownlist-helper-with-aspnet-mvc

In the sample they pass the combobox items in the viewbag.

I recomend you use a jquery plugin like autocomplete or typeahead from twitter bootstrap. So you can load asynchronously the elements.

于 2013-06-11T20:20:54.907 に答える