我在页面的dropdownlist中使用过。
我想,当更改所选的id信息时,加载页面底部。 第一次页面加载为true,但下拉列表更改新页面中的加载信息,而不是当前页面的一部分。
填写下拉列表
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 :(得分: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 })