0

我已经从页面的下拉列表中使用过。

我想,当更改选定的 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>
4

1 回答 1

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 ))

{    

如果您不希望在用户选择任何内容之前执行 ajax 调用,请从目标 div 中删除此行

@Html.Action("selVahedListAjax", new { IdReshte = ViewBag.ChooseItem })
于 2013-08-26T07:37:37.503 回答