Jquery 如何将select html标记转换为html.DropDownList?
如何在html中将此标记转换为@html.DropDownList 选择城市 测试1 测试2Jquery 如何将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.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" }