2016-06-12 10 views
0

選択したプラグインをMultiSelectListに使用しようとしていますが、ビューにプラグインが表示されていても問題があります。なぜあなたはそれを理解できますか?jquery Asp.netで選択したプラグインMVC 4がビューに表示されない

ビュー:

@model test.Models.Employee 
.... 
<script src="~/Scripts/chosen.jquery.min.js"></script> 
<script src="~/Scripts/jquery-1.10.2.min.js"></script> 
<link href="~/Content/chosen.min.css" rel="stylesheet" type="text/css" /> 

<script type="text/javascript"> 
    $(document).ready(function() { 
     $('.chzn-select').chosen(); 
    }); 
</script> 

@using (Html.BeginForm()) 
{ 
    @Html.LabelFor(model => model.Name) 
    @Html.EditorFor(model => model.Name) 
    @Html.ValidationMessageFor(model => model.Name) 

    @Html.LabelFor(model => model.Services) 
    @Html.ListBoxFor(model => model.Services, ViewBag.serviceList as MultiSelectList, 
     new { @class = "chzn-select", id="service", data_placeholder = "Choose Services..." }) 
    @Html.ValidationMessageFor(model => model.Services) 

    <input type="submit" value="Create" class="btn btn-default" /> 
} 

<script> 
    $(".chzn-select").chosen(); 
</script> 

@section Scripts { 
    @Scripts.Render("~/bundles/jqueryval") 
} 

そして、私は適切にユーザーがフォームを送信する場合、サービスフィールドからのデータを結合し、MySQLのテーブルにそれを保存したい場合は、私はpublic IEnumerable>string> Services { get; set; }public string Services { get; set; }のための私のモデルを修正する必要がありますか? IEnumerableを使用して移行したときに、Servicesの列が表示されず、サービスデータの保存について心配しています。

モデル:

public class Employee 
{ 
    [Key] 
    public string EmpId { get; set; } 
    public string Name { get; set; } 
    public string Services { get; set; } 
} 

答えて

1

は自分自身をそれを考え出しました。ネットワークのタブをチェックして、ファイルの一部が読み込まれていないことが判明しました。いくつかのコードを以下のような適切なセクションに置き換える必要があります。

@section Scripts { 
    @Scripts.Render("~/bundles/jqueryval")  
    <script src="@Url.Content("~/Scripts/chosen.jquery.js")" type="text/javascript"></script> 
    <link href="@Url.Content("~/Content/chosen.min.css")" rel="stylesheet" type="text/css" /> 

    <script type="text/javascript"> 
     $(document).ready(function() { 
      $('.chzn-select').chosen(); 
     }); 
    </script> 
} 
+0

My Jqueryの行には何らかの理由で幅も含める必要がありましたが、この回答は大変感謝しています。 $( '.chzn-select')。選択された({幅: "95%"}); – adudley

関連する問題