0

Possible Duplicate:
Razor-based view doesn't see referenced assemblies

I am a Newbie in ASP.net I am trying to connect to a database and I keep getting this error

**Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0103: The name 'Database' does not exist in the current context

Source Error:

Line 1: @{ Line 2: var db = Database.Open("demo"); ' Line 3:
Line 4:

Source File: c:\Users\Ayoya\Documents\My Web Sites\demo\Page.cshtml
Line: 2 **

Can anyone tell me whats wrong? Thank you

Community
  • 1
  • 1
Aya Abdelsalam
  • 502
  • 3
  • 8
  • 21

2 Answers2

0

The compiler's already telling you what's wrong - it doesn't know what you mean by Database. Is that mean to be a property of the page, or is it the name of a type with a static Open method? It's not clear from the code itself, and obviously the compiler can't find the name either.

Work out what name you mean, then work out why the compiler can't see it, then fix that. If you need more help on any of these steps, you'll need to provide more information.

(As an aside, I completely agree with dbaseman: putting database calls in your view is a bad idea.)

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
0

If you're opening a database in your Razor view, that is completely the wrong approach. Your logic should go in the Controller, not the View. Consider creating a "view model" class that contains all the data needed for your view, and populate that class from the Controller.

Probably the reason this piece of code isn't working is that you will need to specify the full namespace of Database. I'm not sure what that class is, though; if it's in a separate DLL, you'll have more problems. Again, though, you should circumvent this problem by putting your database logic in the controller.

McGarnagle
  • 101,349
  • 31
  • 229
  • 260