好的,所以我正在使用 ASP.NET MVC 3 项目。当我第一次开始学习 C# ASP.NET 时,我为控制器操作创建了一个强类型视图。然而,我现在意识到我不再需要那个模型(我的视图被强类型化到的模型)了。我怎样才能摆脱模型?我尝试将它从项目中排除,但是当我在 VS2010 中编译我的项目时,它说The page not found
. 有什么方法可以撤消 VS2010 中的强类型部分,并且仍然能够在我的视图中保留和显示内容?
编辑:
@using IntraNet.Areas.Roc.Models.ViewModels; @* This is for SiteLookupVM *@
@{ Layout = "~/Views/Shared/_LayoutIntranet.cshtml"; }
<div id="mdPageHdr">FindnSave Metrics</div>
@Html.Partial("_PartialSiteLookup", (SiteLookupVm) ViewBag.SiteLookup)
@if (ViewBag.SiteId > 0)
{ @Html.ActionLink("Bounce Metrics", "BounceMetrics", "Metrics",new { siteId = @ViewBag.SiteId }, null)
@Html.Partial("_PartialChartDisplay")
}
else
{
<div id="tabsWrapper">
<ul id="tabs_menu">
<li>@Html.ActionLink("Page Loads", "Index", null, new { id = "active" })</li>
<li>@Html.ActionLink("Metrics Data", "DashMetrics")</li>
</ul>
</div>
<div id='dashboard'>
@Html.Partial("_partialMetricsDashboard")
</div>
}
行动
protected MetricsDashboardRepository _mdr = new MetricsDashboardRepository();
private LoadHistoryDBEntities db = new LoadHistoryDBEntities();
private AvailabilityContext context = new AvailabilityContext();
public ActionResult Index(int? SiteId)
{
SiteLookupVm SiteLookup = new SiteLookupVm();
SiteLookup.ActionName = "Index";
SiteLookup.ControllerName = "Metrics";
ViewBag.SiteLookup = SiteLookup;
ViewBag.Title = "FNS Metrics";
if (SiteId != null && SiteId > 0)
{
string site = new WPDE().Sites.Where(r => r.SiteId == SiteId).Select(r => r.Name).FirstOrDefault();
SiteLookup.CurrentSite = site == null ? "Site does not exist" : site;
ViewBag.SiteId = SiteId;
ViewBag.FnsId = db.fns_sites.Where(f => f.3id == SiteId && f.enabled).Select(s => s.id).FirstOrDefault();
ViewBag.RegionData = context.Regions.ToList();
ViewBag.PathData = context.TestPaths.ToList();
}
else
{
_mdr.DashSetup();
ViewBag.mdr = _mdr;
ViewBag.date = 30;
ViewBag.order = 0;
ViewBag.totPageView = _mdr.TotPageView();
ViewBag.totMonthUni = _mdr.TotMonthUni();
}
return View();
}