Asp.net 下拉列表访问App_DA\ata中存储的数据库表中的数据

Asp.net 下拉列表访问App_DA\ata中存储的数据库表中的数据,asp.net,asp.net-mvc-3,Asp.net,Asp.net Mvc 3,这是我的模型课 公共类模型1 { 公共字符串爆米花{get;set;} 公共字符串pselectedItem{get;set;} 公共IEnumerable项{get;set;} } </fieldset> 这是我的控制器类:- public class HomeController : Controller { private rikuEntities rk = new rikuEntities(); public ActionResult Index()

这是我的模型课 公共类模型1 { 公共字符串爆米花{get;set;} 公共字符串pselectedItem{get;set;} 公共IEnumerable项{get;set;} }

</fieldset>
这是我的控制器类:-

public class HomeController : Controller
{
    private rikuEntities rk = new rikuEntities();
    public ActionResult Index()
    {
        var model = new Model1
        {
            items = new[]
        {
            new SelectList(rk.emp,"Id","name")

        }
        }; return View(model);
    }


    public ActionResult viewToController(Model1 m)
    {
        string getSelectedName = m.popcorn;
        return Content(getSelectedName);
    }


}
</fieldset>
这是我的看法,-

</fieldset>
@模型chetan.Models.Model1 @使用(Html.BeginForm(“viewToController”、“Home”)) { @Html.ValidationSummary(true) 电磁脉冲

    <div class="editor-field">

        @Html.DropDownListFor(x => x.popcorn, new SelectList(Model.items))

    </div>
</fieldset>

@DropDownListFor(x=>x.popcorn,新选择列表(Model.items))

</fieldset>

}

</fieldset>

在我的示例中,我希望从名为“emp”的数据库表中获取Dropdownlist中的值,在选择Dropdownlist的元素后,我希望在Home controller的索引操作中使用该元素。请仔细检查我的代码,并告诉我该怎么做?

首先在您的型号中,您需要的是
选择列表
,而不是
IEnumerable

</fieldset>
在你看来:

</fieldset>
@Html.DropDownListFor(x => x.popcorn, Model.items)
代码的其余部分似乎很好

</fieldset>