2

I am not sure what went wrong but i could not able top use linq in razor view, but i can use linq in controllers.

for example, i cannot run this code

@foreach (char ch in "abcdefghijklmnopqrstuvwxyz".ToCharArray().Where(ch=>ch!='a'))
{

}

or

@Html.EditorFor(e=>e.Id )

any solution for this?

Update: The problem was that, IDE shows red underline where linq is used. but runs without any problem.

1
  • getting method Where is not found and no suitable extension method is available. Commented Mar 6, 2012 at 18:49

1 Answer 1

3

Add the Linq namespace in your view:

@using System.Linq

The System.Linq namespace is in the System.Core assembly (in System.Core.dll)

http://msdn.microsoft.com/en-us/library/system.linq.aspx

Sign up to request clarification or add additional context in comments.

2 Comments

unable to import System.Linq - getting Type or Namespace Linq not available in System.
Just updated my answer - Add a reference, in your project, to the System.Core assembly and it should work...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.