简体   繁体   English

无法将Lambda表达式转换为类型“ Delegate”,因为它不是委托类型MVC 5

[英]Cannot convert lambda expression to type 'Delegate' because it is not a delegate type MVC 5

I know these question(s) has been asked 我知道有人问过这些问题

  1. Cannot convert lambda expression to type 'string' because it is not a delegate type 无法将lambda表达式转换为“字符串”类型,因为它不是委托类型
  2. Entity Framework - Cannot convert lambda expression to type 'string' because it is not a delegate type 实体框架-无法将lambda表达式转换为“字符串”类型,因为它不是委托类型

But none of them has helped me to find the problem that i am facing 但是他们都没有帮助我找到我面临的问题

i have tried to use this solution 我试图使用此解决方案

<div class="form-group">
     @Html.LabelFor(model => model.Postcode_area_name, htmlAttributes: new { @class = "control-label col-md-2" })
    <div class="col-md-10">
 @Html.TextBox(model => model.Postcode_area_name, new { disabled = "disabled", @readonly = "readonly" })
    </div>
</div>

to make one edit field read only, but i do get an error of Cannot convert lambda expression to type 'Delegate' because it is not a delegate type i do use entity frame work and these using 使一个编辑字段为只读,但我确实收到了以下错误:无法将lambda表达式转换为类型“ Delegate”,因为它不是委托类型,所以我使用实体框架,并且使用

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using CRM2.Models;

the suggestion on other questions are that using 关于其他问题的建议是使用

using System.Data.Entity;
using System.Linq;

should fix the problem but it does not work for me I am using MVC 5 应该可以解决问题,但对我不起作用我正在使用MVC 5

i have fixed the issue by using this solution 我已使用此解决方案解决了该问题

@Html.DisplayFor(model => model.Postcode_area_name)
@Html.HiddenFor(model => model.Postcode_area_name)

but because i am new on MVC and entity frame work i want learn why the other way throw an error 但是因为我是MVC和实体框架工作的新手,所以我想了解为什么其他方法会引发错误

Sorry for English "mistake" Thank you 对不起,英语“错误”谢谢

So your original code: 所以你的原始代码:

<div class="form-group">
     @Html.LabelFor(model => model.Postcode_area_name, htmlAttributes: new { @class = "control-label col-md-2" })
    <div class="col-md-10">
         @Html.TextBox(model => model.Postcode_area_name, new { disabled = "disabled", @readonly = "readonly" })
    </div>
</div>

You should change it to: 您应该将其更改为:

<div class="form-group">
     @Html.LabelFor(model => model.Postcode_area_name, htmlAttributes: new { @class = "control-label col-md-2" })
    <div class="col-md-10">
         @Html.TextBoxFor(model => model.Postcode_area_name, new { @readonly = "readonly" })
    </div>
</div>

Note, the addition of For on the TextBox and the removal of disabled = "disabled" 注意,在TextBox上添加了For并删除了disabled = "disabled"

The reason for removing disabled as per @StephenMuecke 根据@StephenMuecke删除disabled的原因

disabled controls do not submit a value 禁用的控件不提交值

The reason for adding For is that it's extension method signature has the first parameter of an expression 添加For的原因是它的扩展方法签名具有表达式的第一个参数

  <div class="form-group">
 @Html.LabelFor(model => model.Postcode_area_name, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
 @Html.TextBoxFor(model => model.Postcode_area_name, new { @readonly = "readonly" })
</div>

As you are using tightly bound entities 当您使用紧密绑定的实体

暂无
暂无

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

相关问题 MVC无法将lambda表达式转换为type,因为它不是委托 - MVC Cannot convert lambda expression to type because it is not a delegate 无法将Lambda表达式转换为类型,因为它不是委托 - Cannot convert lambda expression to type because it is not a delegate 无法将lambda表达式转换为“委托”类型,因为它不是委托类型 - Cannot convert lambda expression to type 'Delegate' because it is not a delegate type 无法将lambda表达式转换为委托类型,因为委托不是类型 - Cannot convert lambda expression to type delegate because delegate is not a type 无法将lambda表达式转换为类型&#39;string&#39;,因为它不是具有NotifyOfPropertyChange的委托类型 - Cannot convert lambda expression to type 'string' because it is not a delegate type With NotifyOfPropertyChange 无法将 lambda 表达式转换为类型“...”,因为它不是委托类型 - Cannot convert lambda expression to type “…” because it is not a delegate type 无法将 lambda 表达式转换为 int 类型,因为它不是委托类型 - Cannot convert lambda expression to type int because it is not a delegate type 无法将lambda表达式转换为类型“CookieAuthenticationOptions”,因为它不是委托类型 - Cannot convert lambda expression to type 'CookieAuthenticationOptions' because it is not a delegate type 无法将lambda表达式转换为类型“字符串”,因为它不是委托类型? - Cannot convert lambda expression to type “string” because it is not a delegate type? 无法将Lambda表达式转换为“ DbContextOptions”类型 <DataContext> ”,因为它不是委托类型 - Cannot convert lambda expression to type “DbContextOptions <DataContext>” because it is not a delegate type
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM