如何在MVC3中加载DropDown [英] How to load DropDown In MVC3

查看:79
本文介绍了如何在MVC3中加载DropDown的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我创建了具有
属性的模型

Hi,

i have created model with properties of

public int Marital_Id { get; set; }
public IList<MaritalStatus> Maritalstatus { get; set; }
  public int Spousestatus_Id { get; set; }
public IList<RelationStatus> Spousestatus { get; set; }



这里的Marital有一个单独的表,名为MaritalStatus
对于Spouse_status,有一个单独的表,名为RelationStatus

那么如何在下拉菜单中加载它

谁能告诉我如何在View Razor引擎和Controller中编写此代码,如何加载此

谢谢



here Marital am having separate table named as MaritalStatus
and for Spouse_status am having separate table named as RelationStatus

so how how i can load this in Drop down

can anyone tell how to write this in View Razor Engine and Controller how can i load this

Thanks

推荐答案

这是一个高级示例:

Here is a high-level example:

@model App.YourModelName

@using(Html.BeginForm())
{
<div>
   @Html.DropDownListFor(m => m.Marital_ID, Model.MaritalStatus)
</div>

<input type="button" value="Go" />
}


在控制器的操作方法中,您可以像这样回读选定的ID:


In your controller''s action method, you can read back the selected id like this:

public ActionMethod(YourModelName yourModel)
{
   // get the selected id from yourModel.Marital_ID
   return View(...);
}



希望这会有所帮助!



Hope this helps!


这篇关于如何在MVC3中加载DropDown的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆