C# 无法将lambda表达式转换为类型';代表';因为它不是委托类型MVC 5
我知道有人问过这些问题 但是没有一个能帮助我找到我所面临的问题 我尝试过使用这个解决方案C# 无法将lambda表达式转换为类型';代表';因为它不是委托类型MVC 5,c#,asp.net-mvc,entity-framework,lambda,C#,Asp.net Mvc,Entity Framework,Lambda,我知道有人问过这些问题 但是没有一个能帮助我找到我所面临的问题 我尝试过使用这个解决方案 <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
<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>
关于其他问题的建议是使用
using System.Data.Entity;
using System.Linq;
应该可以解决这个问题,但对我不起作用
我正在使用MVC5
我已使用此解决方案解决了此问题
@Html.DisplayFor(model => model.Postcode_area_name)
@Html.HiddenFor(model => model.Postcode_area_name)
但是因为我对MVC和实体框架还不熟悉,我想知道为什么另一种方式会抛出错误
对不起,英语“错了”
谢谢
<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>
@LabelFor(model=>model.Postcode_area_name,htmlAttributes:new{@class=“controllabel col-md-2”})
@Html.TextBoxFor(model=>model.Postcode\u area\u name,new{@readonly=“readonly”})
当您使用紧密绑定的实体时
@LabelFor(model=>model.Postcode_area_name,htmlAttributes:new{@class=“controllabel col-md-2”})
@Html.TextBoxFor(model=>model.Postcode\u area\u name,new{@readonly=“readonly”})
由于您使用的是紧密绑定的实体,因此您的原始代码:
<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>
@LabelFor(model=>model.Postcode_area_name,htmlAttributes:new{@class=“controllabel col-md-2”})
@TextBox(model=>model.Postcode\u area\u name,新的{disabled=“disabled”,@readonly=“readonly”})
您应该将其更改为:
<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>
@LabelFor(model=>model.Postcode_area_name,htmlAttributes:new{@class=“controllabel col-md-2”})
@Html.TextBoxFor(model=>model.Postcode\u area\u name,new{@readonly=“readonly”})
注意,在文本框中添加For
,并删除disabled=“disabled”
根据@StephenMuecke删除禁用的原因
禁用的控件不提交值
为
添加的原因是它的扩展方法签名具有表达式的第一个参数,因此原始代码:
<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>
@LabelFor(model=>model.Postcode_area_name,htmlAttributes:new{@class=“controllabel col-md-2”})
@TextBox(model=>model.Postcode\u area\u name,新的{disabled=“disabled”,@readonly=“readonly”})
您应该将其更改为:
<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>
@LabelFor(model=>model.Postcode_area_name,htmlAttributes:new{@class=“controllabel col-md-2”})
@Html.TextBoxFor(model=>model.Postcode\u area\u name,new{@readonly=“readonly”})
注意,在文本框中添加For
,并删除disabled=“disabled”
根据@StephenMuecke删除禁用的原因
禁用的控件不提交值
为
添加的原因是它的扩展方法签名具有表达式的第一个参数您编写的@Html.TextBox
而不是@Html.TextBox
注意
的?@Callum-Linington您是对的,这是我的错误,但是1)当我使用它时,会使文本框非常难看(我知道我可以使用CSS来更改文本框的外观),2)更新不会获取文本框的值,并将值更改为null@RezaDel只要您按照Callum的建议使用@Html.TextBoxFor
,那么DefaultModelBinder应该在您的帖子中正确地分配值,@Html.TextBox
和@Html.TextBoxFor
在Html中的呈现方式不应该有任何不同。它们都将具有name
属性,用于设置为第一个参数的任何对象。2之间的区别是一个允许您手动键入名称
,另一个使用lambda表达式设置名称
@RezaDel,之所以将其设置为null
,是因为您禁用了它(禁用的控件不提交值)-只需新建{@readonly=“readonly”}
你写了@Html.TextBox
而不是@Html.TextBoxFor
注意的你是对的是我的错误,但是1)当我使用它时,会使文本框非常难看(我知道我可以使用CSS来改变文本框的外观),2)更新将不会获取文本框的值,并将该值更改为null@RezaDel只要您按照Callum的建议使用@Html.TextBoxFor
,那么DefaultModelBinder应该在您的帖子中正确地分配值,@Html.TextBox
和@Html.TextBoxFor
在Html中的呈现方式不应该有任何不同。它们都将具有name
属性,用于设置为第一个参数的任何对象。2之间的区别是一个允许您手动键入名称
,另一个使用lambda表达式设置名称
@RezaDel,之所以将其设置为null
,是因为您禁用了它(禁用的控件不提交值)-只需新建{@readonly=“readonly”}
它确实遇到了一个错误,但我不知道为什么它不使用文本框中的数据更新文件,并将其更新为Null您可以与我分享您的控制器方法吗?它确实遇到了一个错误,但我不知道为什么它不使用文本框中的数据更新文件,并将其更新为Null您可以与我分享您的控制器吗方法