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;
}
}
그래서 지금 내가 어디로 가야하는지에 대한 피드백을 얻을 수 있다면, 나는 그것을 고맙게 생각할 것이다.
실제로 * 의사 코드 *보다는 실제 코드가 훨씬 유용합니다. 스택 오버플로는 코드/콘크리트 사물을 보면서 번성합니다. ** 전체 ** 파일을 붙여 넣지 말고 중요하다고 생각하는 부분을 붙여 넣으십시오. ASP.NET MVC 분야를 잘 알고있는 사용자는 아이디어를 얻거나 더 많은 코드를 요구할 때보다 나은 피드백을 제공 할 수 있습니다. – Jesse
일반적으로 클래스에는 자체 .cs 파일이 주어지며 MVC의 모델 폴더에 배치됩니다. "적절한 기능"을 결정하기 위해 "일부 기능"을보아야 할 것입니다. 나는 컨트롤러가 컨트롤러를 사용하는 유일한 곳이라면 그곳에있을 수있을 것입니다. – Shelby115