如何在MVC 4中填写Dropdown。 [英] How do I fill Drop Down In MVC 4.

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

问题描述

我的模型名为AddNoteViewModel,在此模型中我创建了一个notetype列表

I have model Named as AddNoteViewModel and in this model I am creating a List of notetypes

  /// <summary>
 /// Gets or sets note value
 /// </summary>
 [DataMember(Name = "NoteType")]
 public string NoteType { get; set; }



public class Notetypes
{
     public int Id { get; set; }
     public String Name { get; set; }
}
  /// <summary>
 /// Gets or sets note types value
 /// </summary>
[DataMember(Name = "NoteTypes")]
public List<Notetypes> noteTypes { get; set; }



在视图中我想要FilldropDown的notetypes


And in the Views I want to FilldropDown of notetypes

@Html.DropDownListFor(m => m.NoteType,Model.noteTypes)



任何人都可以在此代码中告诉我这里有什么问题。


Can anyone suggest me what is wrong here in this code.

推荐答案

在Viewbag中使用@ html.DropDownList

Using @html.DropDownList with Viewbag
@Html.DropDownList("Mobiledropdown2", ViewBag.VBMobileList as SelectList)  
<pre></pre> 





使用@ html.DropDownListFor使用模型



Using @html.DropDownListFor With Model

@Html.DropDownListFor(M => M.MobileList, new SelectList(Model.MobileList,"Value", "Text"))


这篇关于如何在MVC 4中填写Dropdown。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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