asp.net-mvc – 使用带有剃刀的html选择框
发布时间:2020-12-15 22:27:28 所属栏目:asp.Net 来源:网络整理
导读:我有一个html选择器,我想在我的表单中使用我的“model = model.type”的选定值.有没有办法将我的@ Html.EditorFor(model = model.type)中的值设置为选择器的值? @using (Html.BeginForm()) {@Html.ValidationSummary(true)fieldset legendBet/legend div cl
我有一个html选择器,我想在我的表单中使用我的“model => model.type”的选定值.有没有办法将我的@
Html.EditorFor(model => model.type)中的值设置为选择器的值?
@using (Html.BeginForm()) { @Html.ValidationSummary(true) <fieldset> <legend>Bet</legend> <div class="editor-label"> @Html.LabelFor(model => model.type) </div> <div class="editor-field"> <select id ="type"> <option value="Football">Football</option> <option value="Rugby">Rugby</option> <option value="Horse Racing">Horse Racing</option> </select> @Html.EditorFor(model => model.type) @Html.ValidationMessageFor(model => model.type) </div> <p> <input type="submit" value="Create" /> </p> </fieldset> 解决方法
您可以尝试使用以下选项:
模型: public string Type { get; set; } public IEnumerable<SelectListItem> TypeList { get { return new List<SelectListItem> { new SelectListItem { Text = "Football",Value = "Football"},new SelectListItem { Text = "Rugby",Value = "Rugby"},new SelectListItem { Text = "Horse Racing",Value = "Horse Racing"} }; } } HTML(Razor): @Html.DropDownListFor(model => model.Type,Model.TypeList) 要么 HTML(Razor): @Html.DropDownListFor(model => model.Type,new SelectList(new string[] {"Football","Rugby","Horse Racing"},Model.Type)) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc – 有没有合理的大型Web应用程序(例如1M页面浏
- ASP.NET – Response.Redirect不填充URL引用
- 如何从Asp.Net Code Behind调用JavaScript函数?
- asp.net-mvc – 建立一个在MVC路由之上做出反应的SPA
- asp.net – Razor Host Factory错误
- asp.net-mvc – ASP.NET MVC 2 – Html.DropDownList与View
- asp.net-mvc-3 – 找不到布局页面“{path}”
- asp.net – 在mod_mono和Apache上的Appdomain回收设置
- 实体框架 – 带MVC3的EF4 – 我需要存储库模式吗?
- asp.net – 在方法名称上过滤log4net – 无法得到它