2013-04-22 6 views
1

C# ASP.NET MVC4 사이트를 만들려고합니다. 나는 컨트롤러 파일을 어떻게 배치했는지 정말로 확신 할 수 없다. 여기에 파일이 보이는 방법은 다음과 같습니다Asp.NET MVC4 - "어디로 가야합니까?"

namespace{ 
    *Some Classes that'll be used by the controllers 
    *Controller 
    *ActionResult Index(parameter) 
    *IndexViewModel 
    *Some functions (methods in asp.net?) that make database calls and bundle up 
    the content to be sent to the view 
} 

는 "일부 클래스"와 "일부 기능이"여기 여길 것 같다하지만 난 그들을 넣어 다른 어디 모르겠어요. 어떤 충고? 전체 파일을 붙여 넣는 것이 도움이되는지 알려주세요. 나는 위의 것이 더 쉬울 것이라고 생각했다.

편집 : 통찰력에 감사드립니다. 그래서 나는이 꼼짝 얻을 수 있습니다, 여기에 (당신은 이미 자신의 CS 파일에 가야 지적했다고) 클래스입니다 :

public class contentObject 
{ 
    //The HTML is the content that'll be rendered on the page. 
    public string theHTML { get; set; } 
    //The title is the content's title. 
    public string theTitle { get; set; } 
} 
public class utilityItem 
{ 
    //the menu is the user-specific menu that'll be constructed 
    public string menu { get; set; } 
    //notes is the information about the user/company that might assist the 
    //tech support people 
    public string notes { get; set; } 
    //notice is company-specific text that allows us to communicate with the clients. 
    public string notice { get; set; } 
    //companyName is the company name that'll be displayed 
    public string companyName { get; set; } 
} 
public class listItem 
{ 
    /* listItem is a single entry in the menu will be used to construct the entire menu, 
    which eventually gets bundled into utilityItem.*/ 
    public int theID { get; set; } 
    public string theTitle { get; set; } 
} 

및 기능은 다음과 같이 :

public contentObject buildContent(int TopicID, int userID, HelpSiteEntities1 db) 
    { 
     var queryX = (from H in db.HelpTopics 
         where H.ID == TopicID 
         select new contentObject() { theHTML = H.HTML, theTitle = H.TITLE }).ToArray(); 
     return queryX[0]; 
    } 
    public utilityItem buildUtility(int userID, HelpSiteEntities1 db) 
    { 
     var menu = ""; 
     var queryMenuItems = (from H in db.HelpTopics 
           join P in db.HelpTopicMaps 
           on H.ID equals P.TopicID 
           where P.UserID == userID 
           select new { theID = P.TopicID, theTitle = H.TITLE }).ToList(); 
     var queryVisitorInfo = (from U in db.Users 
           where U.ID == userID 
           select new { notes = U.SpecificNotes, notice = U.Notice, companyName=U.CompanyName }).ToList(); 
     int ittrvar = 0; 
     foreach (var item in queryMenuItems) 
     { 
      menu += "<li><a href='/HelpTopic/Index?TopicID=" + queryMenuItems[ittrvar].theID + "'>" + queryMenuItems[ittrvar].theTitle + "</a></li>"; 
      ittrvar++; 
     } 
     var utility = new utilityItem { menu = menu, notes = queryVisitorInfo[0].notes, notice = queryVisitorInfo[0].notice, companyName=queryVisitorInfo[0].companyName }; 
     return utility; 
    } 
} 

그래서 지금 내가 어디로 가야하는지에 대한 피드백을 얻을 수 있다면, 나는 그것을 고맙게 생각할 것이다.

+3

실제로 * 의사 코드 *보다는 실제 코드가 훨씬 유용합니다. 스택 오버플로는 코드/콘크리트 사물을 보면서 번성합니다. ** 전체 ** 파일을 붙여 넣지 말고 중요하다고 생각하는 부분을 붙여 넣으십시오. ASP.NET MVC 분야를 잘 알고있는 사용자는 아이디어를 얻거나 더 많은 코드를 요구할 때보다 나은 피드백을 제공 할 수 있습니다. – Jesse

+0

일반적으로 클래스에는 자체 .cs 파일이 주어지며 MVC의 모델 폴더에 배치됩니다. "적절한 기능"을 결정하기 위해 "일부 기능"을보아야 할 것입니다. 나는 컨트롤러가 컨트롤러를 사용하는 유일한 곳이라면 그곳에있을 수있을 것입니다. – Shelby115

답변

1

나는 당신이 무엇을 찾고 있는지 잘 모르겠습니다. 당신이 어둠 속에서 캐스팅을하고있어 약간의 지침을 찾고있는 것처럼 보이므로 거기에서 시작하겠습니다.

MVC.NET에는 몇 가지 매우 유용한 규칙이 있으며 Microsoft에서 제공하는 this과 같은 자습서를 통해 빠르게 배울 수 있습니다. Best Practices에도 많은 의견이 있습니다.

기본 출발점은 컨트롤러, 뷰 및 모델을 정의하는 것입니다 (규칙은 각각 동일한 이름의 폴더에 있습니다). 기본 MVC 템플릿에는 HomeController 및 관련 뷰가 있습니다. Scott Gu는 routing에있는 MVC2에 대한 여러 유용한 게시물을 보유하고 있습니다.

MVC를 설정하기로 결정한 경우 비즈니스 논리가 다른 계층에 있으므로 컨트롤러가 다른 곳에서 비즈니스 코드를 호출하여 다른 계층의 데이터베이스 액세스 코드를 호출합니다.

+0

포인터 주셔서 감사합니다. 나는 그 자원들을 조사 할 것이다. – user2305673

관련 문제