我正在尝试制作一个 C# 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;
}
}
所以现在如果我能得到一些关于这些应该去哪里的反馈,我会很感激的。