2013-08-26 93 views
0

我已經從頁面中的下拉列表中使用。DropDown更改顯示部分

我想要更改選定的id信息時,加載頁面底部。 第一次頁面加載是真實的,但下拉更改新頁面中的加載信息,而不是當前頁面的一部分。

填充下拉列表

public ActionResult selVahedList(int IdType, int IdChoose) 
{ 
    ViewBag.ChooseItem = IdChoose; 
    IEnumerable<Lcity> Lcitys = Dbcon.Lcitys; 
    var model = new CityViewMode 
    { 
     Lcitys = Lcitys.Select(x => new SelectListItem 
     { 
      Value = x.Citycode.ToString(), 
      Text = x.CityName 
     }) 
    }; 
    return View(model); 
}); 

局部視圖顯示了在下拉菜單中更改

public ActionResult selVahedListAjax(CityViewMode model) 
    { 
     int idcity=Convert.ToInt32(model.SelectedCitycode); 
     // int idcity = 1; 
     ViewBag.Reshteh = 1; 
     //string IdCity = base.Request["SelValue"].ToString(); 
     var res = Dbcon.TaavoniInfos.Where(m => m.IDReshteh == 1 && m.Citycode ==idcity); 
     return PartialView("selVahedListAjax", res); 
    } 

視圖頁面

AjaxOptions ajaxOpts = new AjaxOptions 
     { 
     UpdateTargetId = "LoadData", 
     LoadingElementId="loadAdmin" 
     }; 
@using (Ajax.BeginForm("selVahedListAjax",ajaxOpts)) 

{ 
    <fieldset> 
<div class="PContent"> 
<p class="DroplistCity" id="DroplistCity"> 

     @Html.DropDownListFor(
     x => x.SelectedCitycode, 
     new SelectList(Model.Lcitys, "Value", "Text","")) 

     <div id="LoadData"> 
     @Html.Action("selVahedListAjax", new { IdReshte = ViewBag.ChooseItem }) 
    </div> 

    </div> 
    </fieldset> 
    } 
    <script language="javascript" type="text/javascript"> 
     $(document).ready(function() { 
      $('#SelectedCitycode').change(function() { 
       this.form.submit(); 
      }); 
     }); 
    </script> 

感謝您的幫助

my partial view code is:           @model 

IEnumerable<TaavonS.Models.TaavoniInfo> 

    <ul> 
    @foreach (var item in Model) 
    { 
      <li>:<b>@Html.DisplayFor(modelItem => item.SName)</b></li> 
     <li>:<b>@Html.DisplayFor(modelItem => item.ModirName)</b></li> 
     <li><img src="@Url.Content("~/Content/img/list16.png")" alt=""/> 
     @Html.ActionLink("detail....", "Detaild",new { codef= item.Scode }, new { @class = "openDialog", data_dialog_id = "emailDialog", data_dialog_title = "" }) 
     <hr class="separatorLine"/></li> when i load page is true but after dropdownlist is nt work 


    <li> 
     @if (!string.IsNullOrEmpty(item.TablighatPic)) 
     { 
     <img src="@Url.Content("~/Content/img/eye.png")"/> @Html.ActionLink("تبلیغات....", "showImg", new { code = item.Scode }, new { @class = "openImg", data_dialog_id = "mailDialog" })<hr class="separatorLine"/> 
     } 
    </li> 
    } 
    </ul> 

回答

0

我認爲你需要改變你的ajaxOptions:

AjaxOptions ajaxOpts = new AjaxOptions 
    { 
    UpdateTargetId = "LoadData", 
    LoadingElementId="loadAdmin", 
    InsertionMode = InsertionMode.Replace // add this line 
    }; 

的參數添加到beginForm呼叫

@using (Ajax.BeginForm("selVahedListAjax", 
     new { IdReshte = ViewBag.ChooseItem }, //add this to the Ajax.BeginForm call 
     ajaxOpts)) 

{  

,並從目標DIV刪除此行如果您不希望在用戶選擇任何內容之前執行ajax呼叫

@Html.Action("selVahedListAjax", new { IdReshte = ViewBag.ChooseItem }) 
+0

謝謝你的幫助,我把插入模式,但沒有解決我的問題 – Raly

+0

忘了提及,你必須將你想顯示在LoadData的div的東西移動到另一個局部視圖,否則,整個頁面被重新插入到目標div – JTMon

+0

我的部分視圖代碼是: – Raly