Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 如何将select html标记转换为html.DropDownList?_Jquery_Asp.net Mvc_Html_Razor - Fatal编程技术网

Jquery 如何将select html标记转换为html.DropDownList?

Jquery 如何将select html标记转换为html.DropDownList?,jquery,asp.net-mvc,html,razor,Jquery,Asp.net Mvc,Html,Razor,如何在html中将此标记转换为@html.DropDownList 选择城市 测试1 测试2 这就是我为下拉列表所做的: 控制器代码: @Html.DropDownListForm=>m.YourProperty,Model.YourSelectList,new{data\u live\u search=true,data\u width=100%,data\u toggle=tooltip,title=Select}使用下划线,而不是连字符这项工作,谢谢Stephen这与OP的问题有什么关系

如何在html中将此标记转换为@html.DropDownList

选择城市 测试1 测试2
这就是我为下拉列表所做的:

控制器代码:


@Html.DropDownListForm=>m.YourProperty,Model.YourSelectList,new{data\u live\u search=true,data\u width=100%,data\u toggle=tooltip,title=Select}使用下划线,而不是连字符这项工作,谢谢Stephen这与OP的问题有什么关系?你想问一个新问题吗?
public ActionResult Contact()
{
    Contact homeViewModel = new Contact();
    homeViewModel.subject = new List<Subject>();
    homeViewModel.subject.Add(new Subject { Id = 1, subject1 = "General Customer Service" });
    homeViewModel.subject.Add(new Subject { Id = 2, subject1 = "Suggestions" });
    homeViewModel.subject.Add(new Subject { Id = 3, subject1 = "Product Support" });

    homeViewModel.Selectedid = 1; //this sets the default value for your dropdown

    return View(homeViewModel);
}
public class Contact
{   
  [Required(ErrorMessage="Please fill the following")]
  public string name { get; set; }
  [Required(ErrorMessage = "Please Enter Correct Username")]
  [RegularExpression(@"^([0-9a-zA-Z]([\+\-_\.][0-9a-zA-Z]+)*)+@(([0-9a-zA-Z][-\w]*[0-9a-zA-Z]*\.)+[a-zA-Z0-9]{2,3})$", ErrorMessage = "Please provide valid email id")]
  public string email { get; set; }
  public List<Subject> subject { get; set; }
  [Required(ErrorMessage="Please fill the following")]
  public string message { get; set; }
  public int Selectedid { get; set; }
}
 @model programname.model.Contact

 @Html.DropDownList("Selectedid", new SelectList(Model.subject, "Id",    "subject1", Model.Selectedid), new { @class = "form-control", id = "subject", required = "required" }