我想做一个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 2013-04-22 01:38:37
一般来说,类都有自己的.cs文件,并放置在MVC的模型文件夹中。我们可能需要查看他们的“某些功能”以确定“正确”的位置。我猜测只要控制器是使用它们的唯一东西,它们可能就位于那里。 – Shelby115 2013-04-22 02:45:11