简体   繁体   English

System.Web.Mvc.HtmlHelper不包含“ DropDownListFor”的定义

[英]System.Web.Mvc.HtmlHelper does not contain a definition for 'DropDownListFor'

I am getting a run time exception as shown below, compiling the source code doesn't show any issues. 我遇到了如下所示的运行时异常,编译源代码不会显示任何问题。 The issue is not happening for @html.TextBoxFor(), why is this happening for DropDownListFor? @ html.TextBoxFor()不会发生此问题,为什么DropDownListFor会发生这种情况?

@Html.DropDownListFor(m => m.EView.EStatusId, @Model.EView.EStatus)
public class EView
{
    #region Constructor

    public EView()
    {
        this.EDataView = new EDataViewModel();
    }

    #endregion

    #region Properties

    public int EStatusId { get; set; }

    public EDataViewModel EDataView { get; set; }

    public IEnumerable<SelectListItem>  EStatus
    {
        get {
            SelectListItem item = null;
            List<SelectListItem> status = null;

            status = new List<SelectListItem>();
            item = new SelectListItem();

            item.Text = "Open";
            item.Value = "1";
            status.Add(item);

            item = new SelectListItem();

            item.Text = "Closed";
            item.Value = "2";
            status.Add(item);
            return status;
        }
    }

    #endregion
}

System.Web.Mvc.HtmlHelper<EApp.ViewModels.AdminViewModel> does not contain a definition for DropDownListFor and the best extension method overload System.Web.Mvc.Html.SelectExtensions.DropDownListFor<TModel,TProperty>(System.Web.Mvc.HtmlHelper<TModel>, System.Linq.Expressions.Expression<System.Func<TModel,TProperty>>, System.Collections.Generic.IEnumerable<System.Web.Mvc.SelectListItem>) has some invalid arguments System.Web.Mvc.HtmlHelper<EApp.ViewModels.AdminViewModel>不包含DropDownListFor的定义和最佳扩展方法重载System.Web.Mvc.Html.SelectExtensions.DropDownListFor<TModel,TProperty>(System.Web.Mvc.HtmlHelper<TModel>, System.Linq.Expressions.Expression<System.Func<TModel,TProperty>>, System.Collections.Generic.IEnumerable<System.Web.Mvc.SelectListItem>)有一些无效的参数

This error can be caused by using the wrong SelectListItem type. 使用错误的SelectListItem类型可能导致此错误。 I inadvertently selected the wrong namespace when I hit Ctrl-. 当我按Ctrl-时,无意中选择了错误的名称空间。 on my unresolved SelectListItem type declaration. 在我未解决的SelectListItem类型声明上。 I selected System.Web.WebPages.Html instead of System.Web.Mvc. 我选择了System.Web.WebPages.Html而不是System.Web.Mvc。 This resulted in the semi-cryptic run-time error in the View. 这导致视图中出现半隐式运行时错误。 The solution is to make sure you are using the correct SelectListItem type in your Controller, ViewModel, etc., by either using the correct namespace in your using statement, or by fully qualifying the SelectListItem type, if needed. 解决方案是通过在using语句中使用正确的名称空间,或通过完全限定SelectListItem类型(如果需要),确保在Controller,ViewModel等中使用正确的SelectListItem类型。 (Hopefully it is not needed...) (希望它不是必需的...)

A bit late I know, but how about dropping the '@' in front of Model.EView.EStatus? 我知道有点晚了,但是在Model.EView.EStatus前面加上'@'怎么样?

So: 所以:

@Html.DropDownListFor(m => m.EView.EStatusId, Model.EView.EStatus)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 CS1928:“ System.Web.Mvc.HtmlHelper”不包含“ DropDownListFor”的定义 - CS1928: 'System.Web.Mvc.HtmlHelper' does not contain a definition for 'DropDownListFor' System.Web.Mvc.HtmlHelper不包含MvcSiteMap的定义 - System.Web.Mvc.HtmlHelper does not contain a definition for MvcSiteMap 系统.Web.Mvc.HtmlHelper<ModelName> 不包含定义 - System.Web.Mvc.HtmlHelper<ModelName> does not contain a definition for System.Web.Mvc.HtmlHelper&#39;不包含CheckBox的定义 - System.Web.Mvc.HtmlHelper' does not contain a definition for CheckBox “System.Web.Mvc.HtmlHelper”不包含“RenderPartial”的定义 - ASP.Net MVC - 'System.Web.Mvc.HtmlHelper' does not contain a definition for 'RenderPartial' - ASP.Net MVC 无法将对象类型“System.Web.Mvc.HtmlHelper` 1 [System.Object]”转换为“System.Web.Mvc.HtmlHelper” - Unable to cast the object type “System.Web.Mvc.HtmlHelper` 1 [System.Object] ”to type“ System.Web.Mvc.HtmlHelper ” “System.Web.Mvc.HtmlHelper”没有名为“Partial”的适用方法 - 'System.Web.Mvc.HtmlHelper' has no applicable method named 'Partial' &#39;System.Web.Mvc.HtmlHelper&#39;没有适用的名为&#39;TextBox&#39;的方法 - 'System.Web.Mvc.HtmlHelper' has no applicable method named 'TextBox' 剃刀视图看不到System.Web.Mvc.HtmlHelper - Razor Views not seeing System.Web.Mvc.HtmlHelper &#39;System.Web.WebPages.Html.HtmlHelper&#39;不包含&#39;ActionLink的定义 - 'System.Web.WebPages.Html.HtmlHelper' does not contain a definition for 'ActionLink
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM