0

I am using the following:

@model IEnumerable<Abc.Service.Shared.Models.Company>

@Html.TextBoxFor(m >= m.Name , new { @id="CompanySearch" })

I get the error:

CS0103: The name 'm' does not exist in the current context

Can anyone help me solve this?


After correcting the arrow, I get another error:

@Html.TextBoxFor(m => m.Name , new { @id="CompanySearch" })

CS0411: The type arguments for method 'System.Web.Mvc.Html.InputExtensions.TextBoxFor<TModel,TProperty>(System.Web.Mvc.HtmlHelper<TModel>, System.Linq.Expressions.Expression<System.Func<TModel,TProperty>>, string)' cannot be inferred from the usage. Try specifying the type arguments explicitly.

Michael Myers
  • 188,989
  • 46
  • 291
  • 292
Anup
  • 9,396
  • 16
  • 74
  • 138

4 Answers4

2

So 2 issues with your code,

  1. as most of the others have pointed out, your syntax error ">="
  2. Your model is a type of IEnumerable<Abc.Service.Shared.Models.Company>. When you do @Html.TextBoxFor, you are trying to get a property from the model. In your case, you are trying to get property "Name" from the model IEnumerable, which obviously won't work.

I assume that Name is a property of your Abc.Service.Shared.Models.Company object and you are trying to display a list of textbox. Here is a reference how you do this: MVC with TextBoxFor having same id within loop

Community
  • 1
  • 1
Jack
  • 2,600
  • 23
  • 29
1

you have syntax issue here,

@Html.TextBoxFor(m >= m.Name , new { @id="CompanySearch" })

should be

@Html.TextBoxFor(m=> m.Name , new { id = "CompanySearch" })

OR

@Html.TextBoxFor(m => m.Name, htmlAttributes: new { id = "CompanySearch" })

and Name should be declared as Public in your Model,this should work for single object only,as you are using Model type as IEnumerable,you should use loop to access object in your Collection

Cris
  • 12,799
  • 5
  • 35
  • 50
  • Got a new error. CS0411: The type arguments for method 'System.Web.Mvc.Html.InputExtensions.TextBoxFor(System.Web.Mvc.HtmlHelper, System.Linq.Expressions.Expression>, string)' cannot be inferred from the usage. Try specifying the type arguments explicitly. Thanks for help – Anup Dec 27 '13 at 05:38
1

you have syntax issue here,

@Html.TextBoxFor(m >= m.Name , new { @id="CompanySearch" })

It should be like this

@Html.TextBoxFor(m => m.Name , new { @id="CompanySearch" })

but you cannot get/use Name property if u use IEnumerable<classname> of ur class in view so thats why it give u error

MaTya
  • 782
  • 6
  • 11
0

Please see the syntax you have used

@Html.TextBoxFor(m >= m.Name , new { @id="CompanySearch" })

It should be like this

@Html.TextBoxFor(m => m.Name , new { @id="CompanySearch" })

See this link for more about MVC

http://www.asp.net/mvc

Ajay
  • 6,418
  • 18
  • 79
  • 130