Error: it is not possible to convert a lambda expression to enter "string" because it is not a delegate type

Error: it is not possible to convert a lambda expression to enter "string" because it is not a delegate type

I get this error when I try to add the cshtml page in mvc4. at line

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

Can someone explain what its meaning is and why it comes here?

Code

@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 the model class;

namespace DataEntryMvcApplication.Models
{
    public class Customer
    {
        public string CustomerId { get; set; }
        public string CustomerName { get; set; }
    }
}
+4
source share
4 answers

You will 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.

+5
source

Modeldoes not exist in the linq expression, which is a parameter @Html.TextBox(...). mrepresents Model, and you need to use this variable to access the correct properties, for example here:

<p>Customer Name: @Html.TextBoxFor(m => m.CustomerName)</p>
<p>ID:@Html.TextBoxFor(m=>m.CustomerId)</p>
+1

Try it,

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

Just spent years trying to solve it. After restoring old pages and making changes one by one, a line appears that causes the problem:

<img src="~/images/Captcha/@ViewBag("CaptchaName")" />

I think you do not need to try to access the bag for viewing? Regardless of commenting on this, the problem is resolved.

0
source

Source: https://habr.com/ru/post/1530010/


All Articles