ParamY Ответов: 0

В MVC, на основе dropdownlist с onChange, после чего я хочу, чтобы заполнить ListView с


Hello , I am using MVC 5 and when I move from first page based on a button click tosecond page I have dropdown to be filed based on ID received from first page and a list of Issues . but now I want to fitler those issues list based on division I selected from the dropdownlist. Can someone please help me with this?


Что я уже пробовал:

<script>
    $(document).ready(function() {
        $("#DropdownDivisionList").change(function () {
            var a = $("#DropdownDivisionList Option:Selected").text();
            $('#span2').text(a);
        })
    })
</script>

<script type="text/javascript">
    $(document).ready(function () {
        $("#DropdownDivisionList").change(function () {
            var division = $(this).val();
            $.getJSON("../Home/GetIssueListByDivision", { division: division },
                   function (data) {
                       var select = $("#span2");
                       select.empty();
                       select.append($('<option/>'));
                       $.each(data, function (index, itemData) {
                           select.append($('<option/>', {
                               value: itemData.Value,
                               text: itemData.Text
                           }));
                       });
                   });
        });
    });
</script>



                <table style="border-color:brown;border-bottom-width:thick">
                    <tr>
                        <td align="center" style="font-size:20px; background: linear-gradient(to right, lightblue, darkblue, lightblue)">
                            <h4 style="color:wheat">Audit Tracking System</h4>
                        </td>
                    </tr>
                    <tr>

                    </tr>
                    <tr>
                        <td align="right">
                            @Html.ActionLink("Home" , "index")  |
                            @Html.ActionLink("Reports", "index") |
                            @Html.ActionLink("Help", "index")
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <span id="span1">@Html.DisplayFor(m => m.strdivision) </span>
                           Division
                             @Html.DropDownListFor(m => m.strdivision, new SelectList(ViewBag.divisionLists),
                               "Please Select Division", new { id = "DropdownDivisionList" ,  @class = "form-control"})
                        </td>
                    </tr>
                    <tr>
                        <td>
                          @Html.Label("Issues")
                        </td>
                    </tr>
                    @*@foreach (var item in ViewBag.issuesList)
                    {
                        <tr>
                            <td>
                                <p>
                                    @item.short_desc
                                </p>
                                @*<span id="span2">@Html.DisplayFor(m => m.strIssue) </span>*@

                                -
                                @*@Html.ActionLink("Edit", "Edit", new { id = item.audit_id }) |
        @Html.ActionLink("Details", "Details", new { id = item.audit_id })  |
        @Html.ActionLink("Delete", "Delete", new { id = item.audit_id })
        <hr style="color:black ; border-color:black" />
    </td>
</tr>}*@
                    @foreach (var item in ViewBag.issuesList)
                    {
                        <tr>
                            <td>
                                <p>
                                @item.short_desc</p>
                                <p>@item.department </p>
                                @*<span id="span2">@Html.DisplayFor(m => m.strIssue) </span>*@

                              -
                                @Html.ActionLink("Edit", "Edit", new { id = item.audit_id }) |
                                @Html.ActionLink("Details", "Details", new { id = item.audit_id })  |
                                @Html.ActionLink("Delete", "Delete", new { id = item.audit_id })
                                <hr style="color:black ; border-color:black" />
                            </td>
                        </tr>
                    }

                </table>


Код CS.
public ActionResult Issues(AuditSearchParameter auditsparam)
{
    var issueList = dbsp.sp_GetAllIssuesbyAuditID(Convert.ToInt32(auditsparam.AuditID)).ToList();
    string zyz = auditsparam.AuditName;
    ViewBag.issuesList = issueList;

    var divisionList = dbsp.sp_getDivisions().ToList();
    ViewBag.divisionLists = divisionList;

    return View();
}

[AcceptVerbs(HttpVerbs.Get)]
public JsonResult GetIssueListByDivision(AuditSearchParameter auditsparam)
{

    var AuditList = dbsp.sp_GetAudits(auditsparam.start_year, auditsparam.InternalExternal);


    var AuditData = AuditList.Select(m => new SelectListItem()
    {
        Text = m.audit_name,
        Value = m.audit_id.ToString(),
    });
    return Json(AuditData, JsonRequestBehavior.AllowGet);

    //var divisionList = dbsp.sp_getDivisions().ToList();
    //ViewBag.divisionLists = divisionList;

    //var AuditList = dbsp.sp_getDivisions();


    //var AuditData = AuditList.Select(m => new SelectListItem());

    //return Json(AuditData, JsonRequestBehavior.AllowGet);
}

0 Ответов