问题转化为editorfor DROPDOWNLIST [英] Problems converting editorfor to dropdownlist

查看:220
本文介绍了问题转化为editorfor DROPDOWNLIST的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请在这里看到达林的解决方案.. <一href=\"http://stackoverflow.com/questions/9517627/converting-html-editorfor-into-a-drop-down-html-dropdownfor\">Converting HTML.EditorFor成一个下拉(html.dropdownfor?)

我不能让下拉列表的工作。可以用这个请任何帮助。谢谢你。

我收到我的ASCX页BC30203错误。

BC30203:标识符。 (4号线 - 新[])..什么我到位模式。我试图把实际的型号名称,可我得到的语法错误..这code根据以上...

张贴的解决方案,链路出现在编辑器模板

code:

 &LT;%= Html.DropDownList(
    ,
   新的SelectList(
   新[]
   {
    新{值=真,文本=是},
    新{值=假,文本=否},
   },
   值,
   文本,
   模型
  )
  )%GT;


解决方案

不知道为什么你得到这样的错误,code应该工作。下面编辑模板工作对我来说完全没有问题,我只是测试它:

 &LT;%@控制语言=C#继承=System.Web.Mvc.ViewUserControl%GT;
&所述;%= Html.DropDownList(
    ,
    新的SelectList(
        新SelectListItem []
        {
            新SelectListItem {值=真,文本=是},
            新SelectListItem {值=假,文本=否}
        },
        值,
        文本,
        模型
    )
)%GT;

与下面的模型:

 公共类MyViewModel
{
    [UIHint(YesNoDropDown)]
    公共布尔IsActive {搞定;组; }
}

控制器:

 公共类HomeController的:控制器
{
    公众的ActionResult指数()
    {
        返回查看(新MyViewModel());
    }
}

和看法:

 &LT;%@页
    语言=C#
    的MasterPageFile =〜/查看/共享/的Site.Master
    继承=System.Web.Mvc.ViewPage&所述; AppName.Models.MyViewModel&gt;中
%GT;&LT; ASP:内容ID =内容1ContentPlaceHolderID =TitleContent=服务器&GT;
    首页
&LT; / ASP:内容&GT;&LT; ASP:内容ID =内容2ContentPlaceHolderID =日程地址搜索Maincontent=服务器&GT;
    &LT;%= Html.EditorFor(型号=&GT; model.IsActive)%GT;
&LT; / ASP:内容&GT;

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.

I am getting BC30203 error in my ascx page.

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...

Code:

 <%= 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
    )
) %>

with the following model:

public class MyViewModel
{
    [UIHint("YesNoDropDown")]
    public bool IsActive { get; set; }
}

controller:

public class HomeController : Controller
{
    public ActionResult Index()
    {
        return View(new MyViewModel());
    }
}

and view:

<%@ 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>

这篇关于问题转化为editorfor DROPDOWNLIST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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