开发者

How do I get my Objects to work in ASP.NET MVC2

开发者 https://www.devze.com 2023-01-09 00:12 出处:网络
I\'m rather new to MVC2 (never been in MCV1) though I\'m a WebForms developer for some years now... in my MCV 2 start project I created a App_Code folder that I would put my Business Classes on it, I

I'm rather new to MVC2 (never been in MCV1) though I'm a WebForms developer for some years now...

in my MCV 2 start project I created a App_Code folder that I would put my Business Classes on it, I also add 2 References to 2 DLLs used for the API I'm about to use.

But I don't get Intellisense on the referenced objects

What am I doing wrong?

alt text http://开发者_如何学编程www.balexandre.com/temp/2010-07-28_1343.png

Is this so much different from the WebForms part?


Added

Even if I put the Object in Models instead App_Code (where I normally put all code in WebForms) I still don't get the normal intelisense, so... it just tells me that something is wrong ... dang! MVC is hard! I probably should do this in WebForms...

alt text http://www.balexandre.com/temp/2010-07-28_1509.png


This has nothing to do with MVC2, and everything to do with you're doing it wrong. I can tell that its a possibility, as you're using App_Code (I mean, who does that?). I'd definitely suggest backing up and reading some MVC tutorials, as it IS much different (although not in the way you're asking about).

I'm not exactly sure WHAT you're doing wrong, however. It might bethat PerceptiveMCAPI is internal to the assembly, it might be because there is a bug in VS, it might be that you haven't imported the correct namespace... it could be a number of different things.

I'd do the following: 1) load the assembly in reflector and make sure you have the namespace and type name and that it is public 2) use the fully qualified name of the type 3) compile, check all errors and 4) restart VS.

If all else fails, Connect.


See the Models directory -- that's where your model classes would go, assuming the class is a view model class. Having said that, it should be able to pick up and provide intellisense for whatever references you add. App_Code isn't really intended for a Web Application project (the type used by MVC) where the code is compiled statically, but rather for a WebSite where the code is compiled dynamically at runtime. It could be the "special" nature of the directory that is causing the problem because it doesn't fit the project type. You might try simply creating a different directory (if Models isn't appropriate) and not use the special App_Code directory for your code. A separate class library project with a project reference in the web application would be another alternative and is the one I usually use for non-viewmodel/controller code.

0

精彩评论

暂无评论...
验证码 换一张
取 消