1

私はMVCページにドロップダウンリストを作成しました.IDを変更したときに、新しいデータを以下のコードでアクションに渡します:

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

私の問題は、選択したアイテムをドロップダウンで取得して渡し、ページのデータを更新できないことです。私を助けてください。どうもありがとう

4

0 に答える 0