MVC错误中的下拉列表

时间:2013-08-24 11:36:28

标签: asp.net-mvc-3

我在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);

} 我的问题是我无法获取并传递下拉菜单中的所选项目并更新页面中的数据。请帮我。 非常感谢

0 个答案:

没有答案