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; }
}
}
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With