【问题标题】:How do I get rid of cannot convert method group "TextBoxFor" to non-delegate type "object"?如何摆脱无法将方法组“TextBoxFor”转换为非委托类型“对象”?
【发布时间】:2015-05-23 22:26:09
【问题描述】:

第一次在 Visual Studio 上使用 asp.net 和 MVC4 试图创建一个简单的表单供客户输入航班预订分配的详细信息,并出现此错误(如下所示)。

我似乎无法修复它,老实说不知道在哪里寻找修复它。是否有另一种方法可以创建更简单的表单,或者有人可以帮助解决这个问题吗?

查看:

@model WebsiteApplicationASSES.Models.customerdetails

@{
    ViewBag.Title = "customerBooking";
}
<!DOCTYPE html />
<html></html>

</div>

<div>
    @using (Html.BeginForm())
    {
        <table>
         <tr>
        <td>  @Html.Label ("First Name:")</td>
        <td>  @Html.TextBoxFor (x=>x.customerFirstName)</td>
       </tr>
    }

型号:

namespace WebsiteApplicationASSES.Models
{
    public class customerdetails
    {
        public string customerFirstName { set; get; }
        public string customerSecondName { set; get; }
        public int customerAge { set; get; }
        public int customerTelephoneNumber { set; get; }
        public string customerEmail { set; get; }
        public int numberOfPassangers { set; get; }
        public int passangersAge { set; get; }


    }
}

""

谢谢!

【问题讨论】:

  • 你有什么错误?
  • 您忘记指定错误。

标签: html asp.net-mvc-4 model-view-controller


【解决方案1】:

尝试删除空格。 Razor 解析器将尝试调用@Html.TextBoxFor 作为方法组并将(x=&gt;x.customerFirstName) 视为文本。

应该是:

@Html.TextBoxFor(x=>x.customerFirstName)


在普通的 C# 中,这会起作用。但是,Razor 单行不能包含空格,除非你用括号括起来:@(Html.TextBoxFor (x=&gt;x.customerFirstName))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-12-24
    • 1970-01-01
    • 1970-01-01
    • 2013-01-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-23
    相关资源
    最近更新 更多