加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc-4 – 错误:无法将lambda表达式转换为’string’类

发布时间:2020-12-16 06:49:55 所属栏目:asp.Net 来源:网络整理
导读:错误:无法将lambda表达式转换为类型’string’,因为它不是委托类型 当我尝试在mvc4中添加cshtml页面时,我收到此错误. 在线客户名称:@ Html.TextBox(m = Model.CustomerName) 任何人都可以解释它的意义是什么以及它为什么来到这里? 代码是 @model DataEntr
错误:无法将lambda表达式转换为类型’string’,因为它不是委托类型

当我尝试在mvc4中添加cshtml页面时,我收到此错误.
在线客户名称:@ Html.TextBox(m => Model.CustomerName)
任何人都可以解释它的意义是什么以及它为什么来到这里?

代码是

@model DataEntryMvcApplication.Models.Customer
@using (Html.BeginForm())
{
    <p>Customer Name: @Html.TextBox(m => Model.CustomerName)</p>
    <p>ID:@Html.TextBox(m=>Model.CustomerId)</p>
    <input type="submit" name="Custtomer" />
}

这是模型类;

namespace DataEntryMvcApplication.Models
{
    public class Customer
    {
        public string CustomerId { get; set; }
        public string CustomerName { get; set; }
    }
}

解决方法

你需要Html.TextBoxFor而不是Html.TextBox:

@model DataEntryMvcApplication.Models.Customer
@using (Html.BeginForm())
{
    <p>Customer Name: @Html.TextBoxFor(m => m.CustomerName)</p>
    <p>ID:@Html.TextBoxFor(m => m.CustomerId)</p>
}

这两者之间的区别在于here

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读