我在 MVC 页面中创建了一个下拉列表,我希望在更改 id 时,使用以下代码将新数据传递给 Action:
@if (ViewBag.IdType==1)
{
@Html.DropDownListFor(m => m.Citycode, new SelectList(ViewBag.ResultList as System.Collections.IEnumerable, "Citycode", "CityName","1"))
@Html.ValidationMessageFor(model => model.Citycode)
}
else
{
@Html.DropDownListFor(m => m.IDReshteh, new SelectList(ViewBag.ResultList as System.Collections.IEnumerable, "IDReshteh", "ReshteName",Model.IDReshteh),"Fselect")
@Html.ValidationMessageFor(model => model.IDReshteh)
}
<input type="hidden" id="SelValue" value="1"/>
<input type="submit" value="Submit" />
</p>
/*<input type="hidden" name="HDcity" id="HDcity" />*/
<div id="LoadData">
@Html.Action("selVahedListAjax", new { IdReshte = ViewBag.ChooseItem, IdCity = Model.IDReshteh })
</div>
模型:
public class TInfo
{
[Key]
public int Id { get; set; }
[Required]
public string Scode { get; set; }
[Required]
public string SName { get; set; }
[Required]
public string TName { get; set; }
public string ModirName { get; set; }
public string FZamineh { get; set; }
public string TAddress { get; set; }
public string PcodeSh { get; set; }
public string TelcodeSh { get; set; }
public string FaxcodeSh { get; set; }
public string DAddress { get; set; }
public string PcodeDa { get; set; }
public string TelcodeDa { get; set; }
public string FaxcodeDa { get; set; }
public string WebsiteAddress { get; set; }
public string EmailAdd { get; set; }
public string TablighatPic { get; set; }
[Required]
public int Citycode { get; set; }
[ForeignKey ("Citycode")]
public Lcity City { get; set; }
[Required]
public int IDReshteh { get; set; }
[ForeignKey("IDReshteh")]
public RFaaliat Reshteh { get; set; }
}
我的控制器://如果 IdType=1 则用户点击 Reshteh 但如果 IdType=2 则用户点击城市
public ActionResult selVahedList(int IdType, int IdChoose)
{
ViewBag.ChooseItem = IdChoose;
ViewBag.IdType = IdType;
if (IdType == 1)
ViewBag.ResultList = Dbcon.Lcitys.ToList();
else
ViewBag.ResultList = Dbcon.RFaaliats.ToList();
return View();
}
public ActionResult selVahedListAjax(int IdReshte,int IdCity )
{
ViewBag.Reshteh = IdReshte;
var res = Dbcon.TaavoniInfos.Where(m => m.IDReshteh == IdReshte && m.Citycode ==?);//Idont know what should put here
return PartialView(res);
我的问题是我无法在下拉列表中获取和传递所选项目并更新页面中的数据。请帮我。多谢