选择/ DROPDOWNLIST不显示 [英] Select/Dropdownlist is not displaying

查看:107
本文介绍了选择/ DROPDOWNLIST不显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当townid可见我无法理解的环节是什么

我有我的网页上,但由于某种奇怪的原因streetid 4下拉列表中是不可见的。真的AP preciate它,如果有人能澄清此事。

查看code

 < H2>创建< / H>
< SCRIPT LANGUAGE =JavaScript的类型=文/ JavaScript的>
功能GetRegions(_countryid){
    VAR procemessage =<期权价值='0'>请稍候...< /选项>中;
    $(#regionid)HTML(procemessage).show();
    VAR URL =/公民/ GetRegions /;    $阿贾克斯({
        网址:网址,
        数据:{countryid:_countryid},
        缓存:假的,
        键入:POST,
        成功:功能(数据){
            VAR的标记=<期权价值='0'>选择地区LT; /选项>中;
            为(变量X = 0; X&下; data.length; X ++){
                标记+ =<期权价值=+数据[X] .value的+>中+数据[X]。文本+< /选项>中;
            }
            如果(标记==<期权价值='0'> LT选择地区; /选项>中)
            {
                标记=<期权价值='0'>无区域中的数据可用于国家< /选项>中;
            }
            $(#regionid)HTML(标记).show();
        },
        错误:功能(效应初探){
            警报(错误:+效应初探);
        }
    });}
功能GetTowns(_regionid){
    VAR procemessage =<期权价值='0'>请稍候...< /选项>中;
    $(#townid)HTML(procemessage).show();
    VAR URL =/公民/ GetTowns /;    $阿贾克斯({
        网址:网址,
        数据:{regionid:_regionid},
        缓存:假的,
        键入:POST,
        成功:功能(数据){
            VAR的标记=<期权价值='0'>选择城市< /选项>中;
            为(变量X = 0; X&下; data.length; X ++){
                标记+ =<期权价值=+数据[X] .value的+>中+数据[X]。文本+< /选项>中;
            }
            如果(标记==<期权价值='0'>选择城市< /选项>){
                标记=<期权价值='0'>无市的可用资料LT地区; /选项>中;
            }
            $(#townid)HTML(标记).show();
        },
        错误:功能(效应初探){
            警报(错误:+效应初探);
        }
    });}
功能GetStreets(_townid){
    VAR procemessage =<期权价值='0'>请稍候...< /选项>中;
    $(#streetid)HTML(procemessage).show();
    VAR URL =/公民/ GetStreets /;    $阿贾克斯({
        网址:网址,
        数据:{tow​​nid:_townid},
        缓存:假的,
        键入:POST,
        成功:功能(数据){
            VAR的标记=<期权价值='0'>选择街道< /选项>中;
            为(变量X = 0; X&下; data.length; X ++){
                标记+ =<期权价值=+数据[X] .value的+>中+数据[X]。文本+< /选项>中;
            }
            如果(标记==<期权价值='0'>选择街道< /选项>){
                标记=<期权价值='0'>没有街道数据可供城市与LT; /选项>中;
            }
            $(#streetid)HTML(标记).show();
        },
        错误:功能(效应初探){
            警报(错误:+效应初探);
        }
    });}
< / SCRIPT>
@using(Html.BeginForm())
@ Html.AntiForgeryToken()@< D​​IV CLASS =形横>
    < H4>公民和LT; / H4>
    <小时/>
    @ Html.ValidationSummary(真,新用{的.class =TEXT-危险})
    < D​​IV CLASS =表单组>
        @ Html.LabelFor(功能(模型)model.CountryId,国家,htmlAttributes:=新增功能{=的.class控制标签COL-MD-2})
        < D​​IV CLASS =COL-MD-10>
            @ Html.DropDownList(CountryID没什么,htmlAttributes:=新增功能{=的.class表格控,.onchange =JavaScript的:GetRegions(THIS.VALUE);})
            @ Html.ValidationMessageFor(功能(模型)model.CountryId,新拥有{的.class =TEXT-危险})
        < / DIV>
    < / DIV>     < D​​IV CLASS =表单组>
         @ Html.LabelFor(功能(模型)model.RegionId,地区,htmlAttributes:=新增功能{=的.class控制标签COL-MD-2})
         < D​​IV CLASS =COL-MD-10>
            <选择一个id =regionidNAME =regionid的onchange =JavaScript的:GetTowns(THIS.VALUE); >
                < /选择>             @ Html.ValidationMessageFor(功能(模型)model.RegionId,新拥有{的.class =TEXT-危险})
         < / DIV>
     < / DIV>     < D​​IV CLASS =表单组>
         @ Html.LabelFor(功能(模型)model.TownId,镇,htmlAttributes:=新增功能{=的.class控制标签COL-MD-2})
         < D​​IV CLASS =COL-MD-10>
             <选择一个id =townidNAME =townid的onchange =JavaScript的:GetStreets(THIS.VALUE); />
             @ Html.ValidationMessageFor(功能(模型)model.TownId,新拥有{的.class =TEXT-危险})
         < / DIV>
     < / DIV>     < D​​IV CLASS =表单组>
         @ Html.LabelFor(功能(模型)model.StreetId,街,htmlAttributes:=新增功能{=的.class控制标签COL-MD-2})
         < D​​IV CLASS =COL-MD-10>
             <选择一个id =streetidNAME =streetid/>
             @ Html.ValidationMessageFor(功能(模型)model.StreetId,新拥有{的.class =TEXT-危险})
         < / DIV>
     < / DIV>
    < D​​IV CLASS =表单组>
        < D​​IV CLASS =COL-MD-偏移2 COL-MD-10>
            <输入类型=提交值=创建类=BTN BTN-默认的/>
        < / DIV>
    < / DIV>
< / DIV>
使用完

在控制器

 < HttpPost>
    公共职能GetRegions(CountryId作为字符串)作为的ActionResult
        昏暗的区域= _db.Regions.Where(功能(R)r.CountryId = CountryId).ToList
        昏暗slstRegions作为新的SelectList(区,ID,区域1,0)
        返回JSON(slstRegions)
    结束功能    < HttpPost>
    公共职能GetTowns(RegionId作为整数)作为的ActionResult
        昏暗的城镇= _db.Towns.Where(功能(T)= t.RegionId RegionId).ToList
        昏暗slstTowns作为新的SelectList(镇,ID,Town1,0)
        返回JSON(slstTowns)
    结束功能    < HttpPost>
    公共职能GetStreets(TownId作为整数)作为的ActionResult
        昏暗的街道= _db.Streets.Where(功能(T)= t.TownId TownId).ToList
        昏暗slstStreets作为新的SelectList(街道,ID,Street1,0)
        返回JSON(slstStreets)
    结束功能    'GET:公民/创建
    功能的Create()为的ActionResult
        ViewBag.AddressId =新的SelectList(GetMyAddresses(_db,User.Identity.GetUserId()),ID,豪斯医生)
        ViewBag.NameId =新的SelectList(_db.Names,ID,名称1)
        ViewBag.SurnameId =新的SelectList(_db.Surnames,ID,Surname1)
        ViewBag.CountryId =新的SelectList(_db.Countries.OrderBy(功能(三)c.country1),ID,国家1)
        返回查看(新CitizenModel)
    结束功能


解决方案

这是我没有找到我的问题虽然不是我喜欢的是设置的东西,所以它不是空白的唯一解决办法

 <选择一个id =streetidNAME =streetid级=表格控>
    <期权价值=0>选择国家< /选项>
< /选择>

然后,我只是简单地覆盖该值时,我申请的JavaScript。如果任何人有一个清洁的解决方案请你告诉我。

I have 4 drop-down lists on my page but for some odd reason streetid is not visible when townid is visible I can't understand what the link is. Would really appreciate it if someone would be able to clarify the matter.

View Code

<h2>Create</h2>
<script language="javascript" type="text/javascript">
function GetRegions(_countryid) {
    var procemessage = "<option value='0'> Please wait...</option>";
    $("#regionid").html(procemessage).show();
    var url = "/Citizens/GetRegions/";

    $.ajax({
        url: url,
        data: { countryid: _countryid },
        cache: false,
        type: "POST",
        success: function (data) {
            var markup = "<option value='0'>Select Region</option>";
            for (var x = 0; x < data.length; x++) {
                markup += "<option value=" + data[x].Value + ">" + data[x].Text + "</option>";
            }
            if (markup == "<option value='0'>Select Region</option>")
            {
                markup = "<option value='0'>No Region Data available for Country</option>";
            }
            $("#regionid").html(markup).show();
        },
        error: function (reponse) {
            alert("error : " + reponse);
        }
    });

}
function GetTowns(_regionid) {
    var procemessage = "<option value='0'> Please wait...</option>";
    $("#townid").html(procemessage).show();
    var url = "/Citizens/GetTowns/";

    $.ajax({
        url: url,
        data: { regionid: _regionid },
        cache: false,
        type: "POST",
        success: function (data) {
            var markup = "<option value='0'>Select Town</option>";
            for (var x = 0; x < data.length; x++) {
                markup += "<option value=" + data[x].Value + ">" + data[x].Text + "</option>";
            }
            if (markup == "<option value='0'>Select Town</option>") {
                markup = "<option value='0'>No Town Data available for Region</option>";
            }
            $("#townid").html(markup).show();
        },
        error: function (reponse) {
            alert("error : " + reponse);
        }
    });

}
function GetStreets(_townid) {
    var procemessage = "<option value='0'> Please wait...</option>";
    $("#streetid").html(procemessage).show();
    var url = "/Citizens/GetStreets/";

    $.ajax({
        url: url,
        data: { townid: _townid },
        cache: false,
        type: "POST",
        success: function (data) {
            var markup = "<option value='0'>Select Street</option>";
            for (var x = 0; x < data.length; x++) {
                markup += "<option value=" + data[x].Value + ">" + data[x].Text + "</option>";
            }
            if (markup == "<option value='0'>Select Street</option>") {
                markup = "<option value='0'>No Street Data available for Town</option>";
            }
            $("#streetid").html(markup).show();
        },
        error: function (reponse) {
            alert("error : " + reponse);
        }
    });

}
</script>
@Using (Html.BeginForm())
@Html.AntiForgeryToken()

@<div class="form-horizontal">
    <h4>Citizen</h4>
    <hr />
    @Html.ValidationSummary(True, "", New With { .class = "text-danger" })
    <div class="form-group">
        @Html.LabelFor(Function(model) model.CountryId, "Country", htmlAttributes:=New With {.class = "control-label col-md-2"})
        <div class="col-md-10">
            @Html.DropDownList("CountryID", Nothing, htmlAttributes:=New With {.class = "form-control", .onchange = "javascript:GetRegions(this.value);"})
            @Html.ValidationMessageFor(Function(model) model.CountryId, "", New With {.class = "text-danger"})
        </div>
    </div>

     <div class="form-group">
         @Html.LabelFor(Function(model) model.RegionId, "Region", htmlAttributes:=New With {.class = "control-label col-md-2"})
         <div class="col-md-10">
            <select id="regionid" name="regionid" onchange="javascript:GetTowns(this.value);" >
                </select>

             @Html.ValidationMessageFor(Function(model) model.RegionId, "", New With {.class = "text-danger"})
         </div>
     </div>

     <div class="form-group">
         @Html.LabelFor(Function(model) model.TownId, "Town", htmlAttributes:=New With {.class = "control-label col-md-2"})
         <div class="col-md-10">
             <select id="townid" name="townid" onchange="javascript:GetStreets(this.value);" />
             @Html.ValidationMessageFor(Function(model) model.TownId, "", New With {.class = "text-danger"})
         </div>
     </div>

     <div class="form-group">
         @Html.LabelFor(Function(model) model.StreetId, "Street", htmlAttributes:=New With {.class = "control-label col-md-2"})
         <div class="col-md-10">
             <select id="streetid" name="streetid" />
             @Html.ValidationMessageFor(Function(model) model.StreetId, "", New With {.class = "text-danger"})
         </div>
     </div>


    <div class="form-group">
        <div class="col-md-offset-2 col-md-10">
            <input type="submit" value="Create" class="btn btn-default" />
        </div>
    </div>
</div>
End Using

In Controller

 <HttpPost>
    Public Function GetRegions(CountryId As String) As ActionResult
        Dim regions = _db.Regions.Where(Function(r) r.CountryId = CountryId).ToList
        Dim slstRegions As New SelectList(regions, "Id", "Region1", 0)
        Return Json(slstRegions)
    End Function

    <HttpPost>
    Public Function GetTowns(RegionId As Integer) As ActionResult
        Dim towns = _db.Towns.Where(Function(t) t.RegionId = RegionId).ToList
        Dim slstTowns As New SelectList(towns, "Id", "Town1", 0)
        Return Json(slstTowns)
    End Function

    <HttpPost>
    Public Function GetStreets(TownId As Integer) As ActionResult
        Dim streets = _db.Streets.Where(Function(t) t.TownId = TownId).ToList
        Dim slstStreets As New SelectList(streets, "Id", "Street1", 0)
        Return Json(slstStreets)
    End Function

    ' GET: Citizens/Create
    Function Create() As ActionResult
        ViewBag.AddressId = New SelectList(GetMyAddresses(_db, User.Identity.GetUserId()), "Id", "House")
        ViewBag.NameId = New SelectList(_db.Names, "Id", "Name1")
        ViewBag.SurnameId = New SelectList(_db.Surnames, "Id", "Surname1")
        ViewBag.CountryId = New SelectList(_db.Countries.OrderBy(Function(c) c.country1), "Id", "Country1")
        Return View(New CitizenModel)
    End Function

解决方案

The only solution that I did find to my problem although not to my liking was to set something so it isn't blank

<select id="streetid" name="streetid" class="form-control">
    <option value="0">Select Country</option>
</select>

Then I just overwrite the value when I am applying JavaScript. If anyone has a cleaner solution please do tell me.

这篇关于选择/ DROPDOWNLIST不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆