本文介绍了传递所选下拉选项的ID并将其发送给控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!我是mvc3的新手,正在创建搜索模块....
在我的表格中,我有两个下拉列表,分别称为州和地区,而地区取决于州的选择....
我已经为州和地区创建了视图模型

Hi to all! I''m new to mvc3 and i am creating the search module....
In my form i have two drop down list called state and district where district depend on selection of state....
I have created view model for state and district

public class State_district
    {

       public int selectedDistrictid{get;set;}
        public IEnumerable<State> states { get; set; }
        public State stateid{ get; set; }
        public string selectedstate { get; set; }
        public IEnumerable<District> districts{get;set;}
        public District distId { get; set; }

    }


在控制器中:


in the controller:

public ActionResult Index()
        {
            var model = new State_district { states = db.States, districts = from m in db.Districts select m };
            return View(model);
        }


在视图中,我使用以下命令调用下拉菜单:


and in the view , i am calling the dropdown using following:

<div class="editor-field">*Select State:-
           @Html.DropDownListFor(x => x.states, new SelectList(Model.states, "Id", "State_Name"), new {id = "states"})

          </div>


我想获取所选州的ID和District-ID的值,并取决于我需要从我的数据库表中获取结果.所以我需要将此值传递给控制器​​,其中其他操作链接将有助于从表中查找数据

有人可以帮我吗.....


I want to get value of selected state''s id and district-id and depending on that i need to get result from my database table. so i need to pass this value to controller where other action link will help to find data from table

Can someone help me with this.....

推荐答案


这篇关于传递所选下拉选项的ID并将其发送给控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 04:11
查看更多