将编辑器转换为下拉列表时出现问题 [英] Problems converting editorfor to dropdownlist
问题描述
请参阅Darin的解决方案。转换HTML.EditorFor进入下拉列表(html.dropdownfor?)
Please see Darin's solution here .. Converting HTML.EditorFor into a drop down (html.dropdownfor?)
我无法使下拉列表工作。可以帮助这个请。谢谢。
I am not able to make the drop down list work. Can any help with this please. Thank you.
我的ascx页面中有BC30203错误。
I am getting BC30203 error in my ascx page.
BC30203:预期的标识符。 (第4行 - 新的[])..我用什么代替模型。我尝试放置实际的模型名称,可能是我的语法错误..这个代码进入编辑器模板根据上面的解决方案链接...
BC30203: Identifier expected. (Line 4 - new[] ).. What do I put in place of model. I tried putting the actual model name and may be I am getting the syntax wrong.. this code goes in the editor template according to the posted solution link above...
代码:
<%= Html.DropDownList(
"",
new SelectList(
new[]
{
new { Value = "true", Text = "Yes" },
new { Value = "false", Text = "No" },
},
"Value",
"Text",
Model
)
) %>
推荐答案
不知道为什么你得到这样的错误,代码应该工作以下编辑器模板对我来说完全正常,我刚刚测试过:
No idea why you are getting such error, the code should work. The following editor template works perfectly fine for me, I have just tested it:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<%= Html.DropDownList(
"",
new SelectList(
new SelectListItem[]
{
new SelectListItem { Value = "true", Text = "Yes" },
new SelectListItem { Value = "false", Text = "No" }
},
"Value",
"Text",
Model
)
) %>
与以下型号:
public class MyViewModel
{
[UIHint("YesNoDropDown")]
public bool IsActive { get; set; }
}
控制器:
public class HomeController : Controller
{
public ActionResult Index()
{
return View(new MyViewModel());
}
}
并查看:
<%@ Page
Language="C#"
MasterPageFile="~/Views/Shared/Site.Master"
Inherits="System.Web.Mvc.ViewPage<AppName.Models.MyViewModel>"
%>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Home Page
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<%= Html.EditorFor(model => model.IsActive) %>
</asp:Content>
这篇关于将编辑器转换为下拉列表时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!