本文整理汇总了C#中System.Web.Mvc类的典型用法代码示例。如果您正苦于以下问题:C# System.Web.Mvc类的具体用法?C# System.Web.Mvc怎么用?C# System.Web.Mvc使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
System.Web.Mvc类属于命名空间,在下文中一共展示了System.Web.Mvc类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetupRazor
/* Eliminated all vbhtml and aspx, and unused locations, and engines*/
private static void SetupRazor()
{
ViewEngines.Engines.Clear();
var razor = new PrecompiledMvcEngine(typeof(Mvc).Assembly)
{
UsePhysicalViewsIfNewer = true
};
ViewEngines.Engines.Insert(0, razor);
// StartPage lookups are done by WebPages.
VirtualPathFactoryManager.RegisterVirtualPathFactory(razor);
// Not using areas, not using vbhtmls.
var areaViewLocations = new string[0];
var viewLocations = new[] { "~/Views/{1}/{0}.cshtml", "~/Views/Shared/{0}.cshtml" };
razor.AreaMasterLocationFormats = areaViewLocations;
razor.AreaPartialViewLocationFormats = areaViewLocations;
razor.AreaViewLocationFormats = areaViewLocations;
razor.MasterLocationFormats = viewLocations;
razor.PartialViewLocationFormats = viewLocations;
razor.ViewLocationFormats = viewLocations;
ViewEngines.Engines.Add(razor);
}
示例2: Initialize
public static void Initialize()
{
if (_initialized)
return;
var namespaces = new[] { "HipChat.Widget.Mvc" };
var routes = RouteTable.Routes;
var hipChatWidgetRoute = Settings.Route;
routes.MapRoute(
"HipChat.Widget.Mvc",
string.Format("{0}/{{resource}}", hipChatWidgetRoute),
new
{
controller = "HipChatWidget",
action = "Chat",
resource = UrlParameter.Optional
},
null,
namespaces);
if (hipChatWidgetRoute != "HipChatWidget" && Settings.IgnoreDefaultRoute)
{
routes.IgnoreRoute("HipChatWidget");
routes.IgnoreRoute("HipChatWidget/{*pathinfo}");
}
_initialized = true;
}
示例3: RegisterArea
public override void RegisterArea(AreaRegistrationContext context)
{
RegisterIoc();
var ns = new[] { "MvcSolution.Web.Admin.Controllers.*" };
var defaults = new {controller = "home", action = "index", id = UrlParameter.Optional};
context.Map("admin/{controller}/{action}/{id}", defaults, ns);
}
示例4: RegisterRoutes
protected override void RegisterRoutes(RouteCollection routes)
{
var defaults = new { controller = "home", action = "index", id = UrlParameter.Optional };
var ns = new[] { "MvcSolution.Web.Public.Controllers.*" };
routes.Map("{controller}/{action}/{id}", defaults, ns);
}
示例5: Index
public ActionResult Index()
{
var movies = new[] {
new Movie {
Title = "The Big Lebowski",
ReleaseDate = "1998",
RunningTime = "117 mins",
Actors = new[] {
new Actor("Jeff Bridges"),
new Actor("John Goodman"),
new Actor("Steve Buscemi"),
}
},
new Movie {
Title = "The Princess Bride",
ReleaseDate = "1987",
RunningTime = "98 mins",
Actors = new[] {
new Actor("Cary Elwes"),
new Actor("Many Patinkin"),
new Actor("Robin Wright"),
}
},
};
return View(movies);
}
示例6: ResetDatabase
public ActionResult ResetDatabase(FormCollection form)
{
NHibernateBootstrapper.CreateSchema();
using (var session = NHibernateBootstrapper.GetSession())
{
var users = new[]
{
Core.Domain.User.CreateNewUser("[email protected]", "admin"),
Core.Domain.User.CreateNewUser("[email protected]", "user")
};
users.ForEach(u => session.Save(u));
var project = Project.Create("Fail Tracker", users[0]);
session.Save(project);
(new[] {
Issue.CreateNewIssue(project, "Project support", users[0], "As someone who manages many software projects, I want to be able to organize issues and bugs into projects within Fail Tracker.")
.ReassignTo(users[0])
.ChangeSizeTo(PointSize.Eight),
Issue.CreateNewIssue(project, "Site rendering problems in IE6", users[1], "The site does not render the same in al versions of IE!")
.ChangeTypeTo(IssueType.Bug)
.ChangeSizeTo(PointSize.OneHundred)
.ReassignTo(users[1]),
Issue.CreateNewIssue(project, "Enable user invite", users[0], "I want to be able to invite users to join Fail Tracker through a form on the site.")
.ReassignTo(users[0])
.ChangeSizeTo(PointSize.Five),
Issue.CreateNewIssue(project, "Support unassigned stories", users[0], "I want to be able to leave stories and bugs unassigned.")
.ChangeSizeTo(PointSize.Five),
}).ForEach(i => session.Save(i));
session.Flush();
}
return this.RedirectToAction<DashboardController>(c => c.Index());
}
示例7: RegisterRoutes
public static void RegisterRoutes(RouteCollection routes)
{
// Local variable of an array of strings that contains the namespace
// of wherever our PostsController namespace exists. When namespaces is
// passed into the routes below, they'll be targeting a specific folder.
// This is done to avoid conflicts as more than one PostsController exist.
var namespaces = new[] { typeof(PostsController).Namespace };
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute("Login", "login", new { controller = "Auth", action = "Login" }, namespaces);
routes.MapRoute("Logout", "logout", new { controller = "Auth", action = "Logout" }, namespaces);
routes.MapRoute("Home", "", new { controller = "Posts", action = "Index" }, namespaces);
// The default route will not be used.
// All routes in this application will be explicit, which
// allows the developer to have more control.
//routes.MapRoute(
// name: "Default",
// url: "{controller}/{action}/{id}",
// defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
//);
}
示例8: RegisterRoutes
public static void RegisterRoutes(RouteCollection routes)
{
var namespaces = new[] { "Branch.App.Controllers" };
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
AreaRegistration.RegisterAllAreas();
// Welcome
routes.MapRoute("Welcome", "Home/",
new { controller = "Home", action = "Index" }, namespaces);
// Blog
routes.MapRoute("Blog", "Blog/View/{slug}",
new { controller = "Blog", action = "View", slug = "welcome" }, namespaces);
// Search
routes.MapRoute("SearchIdentity", "Search/Identity/{ident}",
new { controller = "Search", action = "Identity", ident = UrlParameter.Optional }, namespaces);
routes.MapRoute("Search", "Search/",
new { controller = "Search", action = "Index" }, namespaces);
// Catch All
routes.MapRoute("Default", "{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional }, namespaces);
}
示例9: MoreVehicles
public ActionResult MoreVehicles()
{
var vehicles = new[]
{
new Vehicle
{
Name = "1968 Pontiac Firebird",
Type = "Classic Car",
Price = 27499.99m,
Components = new[]
{
new Component {Name = "8 cyl. Engine", Color = "Red"},
new Component {Name = "Interiors", Color = "Cameo Ivory"},
new Component {Name = "Exteriors", Color = "Autumn Bronze"}
}
},
new Vehicle
{
Name = "WW-II Seehund U-Boat",
Type = "German Midget Submarine",
Price = 2579000m,
Components = new[]
{
new Component {Name = "Torpedo", Color = "Gray"},
new Component {Name = "Torpedo", Color = "Gray"},
new Component {Name = "Torpedo", Color = "Gray"},
new Component {Name = "Torpedo", Color = "Black"},
}
},
};
return Json(vehicles, JsonRequestBehavior.AllowGet);
}
示例10: Index
public ActionResult Index()
{
Vehicle[] vehicles = new[]
{
new Vehicle
{
Name = "Schinn Fixed Bicycle",
Type = "Bicycle",
Price = 199.99m,
Components = new[]
{
new Component {Name = "Speed Gauge", Color = "Red"},
new Component {Name = "Pedal", Color = "Black"},
new Component {Name = "Big Wheel", Color = "Dark Red"}
}
},
new Vehicle
{
Name = "Predator",
Type = "Fighter Drone",
Price = 1650000.99m,
Components = new[]
{
new Component {Name = "Autopilot", Color = "None"},
new Component {Name = "Missile Battery", Color = "Black"},
}
},
};
return View(vehicles);
}
示例11: PreviewBriefArticle
public ActionResult PreviewBriefArticle(int articleId)
{
var articles = new[] {
articlesService.GetById(articleId)
};
return View("~/Views/Articles/Articles.cshtml", articles);
}
示例12: RegisterRoutes
public static void RegisterRoutes(RouteCollection routes)
{
var namespaces = new[] {typeof (PostsController).Namespace};
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute("TagForRealThisTime", "tag/{idAndSlug}", new { controller = "Posts", action = "Tag" },
namespaces);
routes.MapRoute("Tag", "tag/{id}-{slug}", new { controller = "Posts", action = "Tag" }, namespaces);
routes.MapRoute("PostForRealThisTime", "post/{idAndSlug}", new {controller = "Posts", action = "Show"},
namespaces);
routes.MapRoute("Post", "post/{id}-{slug}", new { controller = "Posts", action = "Show" }, namespaces);
routes.MapRoute("Login", "login", new {controller = "Auth", action = "Login"}, namespaces);
routes.MapRoute("Logout", "logout", new { controller = "Auth", action = "Logout" }, namespaces);
//empty route "" means the one that shows up when nothing is specified
routes.MapRoute("Home", "", new { controller = "Posts", action = "index" }, namespaces);
routes.MapRoute("Sidebar", "", new { controller = "Layout", action = "Sidebar" }, namespaces);
routes.MapRoute("Error500", "errors/500", new {controller="Errors", action="Error"}, namespaces);
routes.MapRoute("Error404", "errors/404", new {controller="Errors", action="NotFound"}, namespaces);
}
示例13: CreateActionResultWithObjectReturnsSomethingElse
public void CreateActionResultWithObjectReturnsSomethingElse()
{
var actionDescriptor = MockRepository.GenerateStub<ActionDescriptor>();
object actionReturnValue = new {};
var actionResult = _actionInvoker.CreateActionResult(null, actionDescriptor, actionReturnValue);
Assert.That(actionResult, Is.Not.EqualTo(actionReturnValue));
}
示例14: CustomRazorViewEngine
public CustomRazorViewEngine()
{
var viewLocations = new[]
{
"~/Views/{0}.cshtml",
"~/Views/{1}/{0}.cshtml",
"~/Views/Menu/{0}.cshtml",
//"~/Views/Carlos/{1}/{0}.cshtml",
//"~/Views/Carlos/Shared/{0}.cshtml",
};
this.ViewLocationFormats = viewLocations;
this.PartialViewLocationFormats = viewLocations;
#region AREAs
//var areaViewLocations = new[]
//{
// "~/Views/Carlos/{1}/{0}.cshtml",
// "~/Views/Carlos/Shared/{0}.cshtml",
// "~/Views/{2}/{1}/{0}.cshtml", // Coping with Area's
// "~/Views/{2}/Shared/{0}.cshtml"
//};
//this.AreaPartialViewLocationFormats = areaViewLocations;
//this.AreaViewLocationFormats = areaViewLocations;
#endregion
}
示例15: MoreMovies
public ActionResult MoreMovies()
{
var movies = new[] {
new Movie {
Title = "Rounders",
ReleaseDate = "1998",
RunningTime = "121 mins",
Actors = new[] {
new Actor("Matt Damon"),
new Actor("Edward Norton"),
new Actor("John Malcovich"),
}
},
new Movie {
Title = "Batman",
ReleaseDate = "1989",
RunningTime = "126 mins",
Actors = new[] {
new Actor("Michael Keaton"),
new Actor("Jack Nicholson"),
}
},
};
return Json(movies, JsonRequestBehavior.AllowGet);
}