本文介绍了基于dropdownlist onchange的Mvc我想填写listview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在使用MVC 5,当我从第一页移动时,根据按钮点击第二页,我根据从第一页收到的ID提交下拉列表和问题清单。但现在我想根据我从下拉列表中选择的部门列出那些问题列表。有人可以帮我这个吗?





我尝试过:



< 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 =边框颜色:褐色;边界底部宽度:厚> 
< tr>
< td align =centerstyle =font-size:20px; background:linear-gradient(to right,lightblue,darkblue,lightblue)>
< h4 style =color:wheat>审计跟踪系统< / h4>
< / td>
< / tr>
< tr>

< / tr>
< tr>
< td align =right>
@ Html.ActionLink(主页,索引)|
@ Html.ActionLink(报告,索引)|
@ Html.ActionLink(帮助,索引)
< / 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(问题)
< / td>
< / tr>
@ * @ foreach(ViewBag.issuesList中的var项目)
{
< tr>
< td>
< p>
@ item.short_desc
< / p>
@ *< span id =span2> @ Html.DisplayFor(m => m.strIssue)< / span> * @

-
@ *@Html.ActionLink(编辑,编辑,新{id = item.audit_id})|
@ Html.ActionLink(详细信息,详细信息,新{id = item.audit_id})|
@ Html.ActionLink(删除,删除,新{id = item.audit_id})
< hr style =color:black; border-color:black/>
< / td>
< / tr>} * @
@foreach(ViewBag.issuesList中的var项目)
{
< tr>
< td>
< p>
@ item.short_desc< / p>
< p> @ item.department< / p>
@ *< span id =span2> @ Html.DisplayFor(m => m.strIssue)< / span> * @

-
@ Html.ActionLink(编辑,编辑,新{id = item.audit_id})|
@ Html.ActionLink(详细信息,详细信息,新{id = item.audit_id})|
@ Html.ActionLink(删除,删除,新{id = item.audit_id})
< hr style =color:black; border-color:black/>
< / td>
< / tr>
}

< / table>





CS代码。

公共ActionResult问题(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(),
});
返回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());

//返回Json(AuditData,JsonRequestBehavior.AllowGet);
}
解决方案




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?



What I have tried:

<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 code.

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);
}
解决方案




这篇关于基于dropdownlist onchange的Mvc我想填写listview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 13:04