vb.net - Namespace conflicts in Asp.net MVC -
i long-time semi-professional asp.net programmer has made leap asp.net forms environment mvc. in process of re-developing 1 of web apps exists in forms mvc, , liking mvc environment , glad making leap.
but...am encountering issues, 1 namespaces.
so let's imagine following: 1) create new mvc 4 project called mymvcproject 2) create app_code folder , add new class1.vb file follows:
namespace mynamespace public class class1 property myproperty string end class end namespace
ok far good. want access class in controller or follows:
imports mynamespace public class default1controller inherits system.web.mvc.controller function index() actionresult dim obj new class1 return view() end function end class
in asp.net forms environment, go. however, in mvc project unable import "mynamespace" , therefore unable create class1. go looking , find following in object browser:
>[other references...] v[vb] mymvcproject >{}mymvcproject >{}mymvcproject.my >{}mymvcproject.my.resources v[vb] mymvcproject v{}mynamespace > [] class1 >[other references...]
so there's "mynamespace" , "class1." attempt revise code follows:
imports mymvcproject.mynamespace public class default1controller inherits system.web.mvc.controller function index() actionresult dim obj new class1 return view() end function end class
but doesn't help. able reference first instance mymvcproject , it's sub-references. not second "class1" resides. uncertain how fix this.
update 1: found solution (but not explanation) whatever reason, asp.net mvc not me put stuff in app_code folder. however, if put class1.vb in models folder can can import "mymvcproject.mynamespace" , proceed normally. object browswer looks this:
>[other references...] v[vb] mymvcproject >{}mymvcproject >{}mymvcproject.my >{}mymvcproject.my.resources v{}mymvcproject.mynamespace > [] class1 v[vb] mymvcproject >[other references...]
notice second reference mymvcproject still exists. "mynamespace" , classes put under first instance, can reference , import normally. kind of quirky, seems me. if have throw in models folder, well, i'll it.
update 2 had know problem putting stuff in app_code folder, have found answers: asp.net mvc using app_code directory
update 3
all mvc project default web application projects (wap) instead of web site projects. means there's no need app_code folder since waps compiled anyway. means *.cs files in project compiled, opposed web site projects *.cs files in app_code folder compiled.
source: http://forums.asp.net/t/1315143.aspx?mvc+and+app_code+folder
update 4 , here how include app_code folder in mvc project:
you have go @ properties section of file , build action change content compile. ;)
source: http://how-to-code-net.blogspot.mx/2014/04/appcode-classes-not-available-in-aspnet.html
Comments
Post a Comment