[英]Cannot convert lambda expression to type 'Delegate' because it is not a delegate type MVC 5
I know these question(s) has been asked 我知道有人问过这些问题
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.