Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Cannot convert lambda expression to type 'string' because it is not a delegate type

Error:Cannot convert lambda expression to type 'string' because it is not a delegate type

I am getting this error when I am trying to add in cshtml page in mvc4. at line

Customer Name: @Html.TextBox(m => Model.CustomerName)

Could anyone explain what is its meaning and why it comes here?

Code is

@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" />
}

and this is model class;

namespace DataEntryMvcApplication.Models
{
    public class Customer
    {
        public string CustomerId { get; set; }
        public string CustomerName { get; set; }
    }
}
like image 848
ADP Avatar asked Mar 21 '23 08:03

ADP


1 Answers

You'll need Html.TextBoxFor instead of 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>
}

The difference between the two is explained here

like image 112
Bruno V Avatar answered Mar 22 '23 23:03

Bruno V