1.MVC设计典范:

MVC的全称模型(model)-视图(view)-控制器(controller),是一种设计典范.
它是用一种业务逻辑、数据与页面显示分离的方法来组织代码,
将众多的业务逻辑聚集到一个部件里面,在需要改进和定制化页面以及用户的交互时,
不需要重新编写业务逻辑.

2.MVC简介以及示意图:

2.1简介:

(Model-View-Controller)是软件工程中的一种软件架构模式,把软件系统分为三个基本部分:模型(Model)、视图(View)和控制器(Controller)。

2.2: MVC模式的目的是实现一种动态的程序设计,使后续对程序的修改和扩展简化,并且使程序某一部分的重复利用成为可能。除此之外,此模式通过对复杂度的简化,使程序结构更加直观。软件系统通过对自身基本部份分离的同时也赋予了各个基本部分应有的功能。专业人员可以通过自身的专长分组三层:

(控制器Controller)- 负责转发请求,对请求进行处理。

(视图View) - 界面设计人员进行图形界面设计。

(模型Model) - 程序员编写程序应有的功能(实现算法等等)、数据库专家进行数据管理和数据库设计(可以实现具体的功能)。

2.2:简单的示意图:

2.3:

3.MVC分别代表什么?

1.视图:

视图是用户看到并与之交互的界面。对老式的Web应用程序来说,视图就是由HTML元素组成的界面,在新式的Web应用程序中,HTML依旧在视图中扮演着重要的角色,但一些新的技术已层出不穷,它们包括Macromedia
Flash和像XHTML,XML/XSL,WML等一些标识语言和Web services.
如何处理应用程序的界面变得越来越有挑战性。MVC一个大的好处是它能为你的应用程序处理很多不同的视图。在视图中其实没有真正的处理发生,不管这些数据是联机存储的还是一个雇员列表,作为视图来讲,它只是作为一种输出数据并允许用户操纵的方式。

2.模型:

模型表示企业数据和业务规则。在MVC的三个部件中,模型拥有最多的处理任务。例如它可能用像EJBs和ColdFusion
Components这样的构件对象来处理数据库。被模型返回的数据是中立的,就是说模型与数据格式无关,这样一个模型能为多个视图提供数据。由于应用于模型的代码只需写一次就可以被多个视图重用,所以减少了代码的重复性。

3.控制器:

控制器接受用户的输入并调用模型和视图去完成用户的需求。所以当单击Web页面中的超链接和发送HTML表单时,控制器本身不输出任何东西和做任何处理。它只是接收请求并决定调用哪个模型构件去处理请求,然后确定用哪个视图来显示模型处理返回的数据。
  现在我们总结MVC的处理过程,首先控制器接收用户的请求,并决定应该调用哪个模型来进行处理,然后模型用业务逻辑来处理用户的请求并返回数据,最后控制器用相应的视图格式化模型返回的数据,并通过表示层呈现给用户。

4. MVC优点和缺点:

5.MVC的核心代码:

【核心代码】
// Copyright © Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.

*using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.Contracts;
using System.Globalization;
using System.IO;
using System.Security.Principal;
using System.Text;
using System.Web.Mvc.Async;
using System.Web.Mvc.Filters;
using System.Web.Mvc.Properties;
using System.Web.Mvc.Routing;
using System.Web.Profile;
using System.Web.Routing;

using System.Web.WebPages;*

namespace System.Web.Mvc
{
[SuppressMessage(“Microsoft.Maintainability”, “CA1506:AvoidExcessiveClassCoupling”, Justification = “Class complexity dictated by public surface area”)]
public abstract class Controller : ControllerBase, IActionFilter, IAuthenticationFilter, IAuthorizationFilter, IDisposable, IExceptionFilter, IResultFilter, IAsyncController, IAsyncManagerContainer
{
private static readonly object _executeTag = new object();
private static readonly object _executeCoreTag = new object();

    private readonly AsyncManager _asyncManager = new AsyncManager();private IActionInvoker _actionInvoker;private ModelBinderDictionary _binders;private RouteCollection _routeCollection;private ITempDataProvider _tempDataProvider;private ViewEngineCollection _viewEngineCollection;private IDependencyResolver _resolver;/// <summary>/// Represents a replaceable dependency resolver providing services./// By default, it uses the <see cref="DependencyResolver.CurrentCache"/>. /// </summary>public IDependencyResolver Resolver{get { return _resolver ?? DependencyResolver.CurrentCache; }set { _resolver = value; }}public AsyncManager AsyncManager{get { return _asyncManager; }}/// <summary>/// This is for backwards compat. MVC 4.0 starts allowing Controller to support asynchronous patterns./// This means ExecuteCore doesn't get called on derived classes. Derived classes can override this/// flag and set to true if they still need ExecuteCore to be called./// </summary>protected virtual bool DisableAsyncSupport{get { return false; }}public IActionInvoker ActionInvoker{get{if (_actionInvoker == null){_actionInvoker = CreateActionInvoker();}return _actionInvoker;}set { _actionInvoker = value; }}[SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly", Justification = "Property is settable so that the dictionary can be provided for unit testing purposes.")]protected internal ModelBinderDictionary Binders{get{if (_binders == null){_binders = ModelBinders.Binders;}return _binders;}set { _binders = value; }}public HttpContextBase HttpContext{get { return ControllerContext == null ? null : ControllerContext.HttpContext; }}public ModelStateDictionary ModelState{get { return ViewData.ModelState; }}public ProfileBase Profile{get { return HttpContext == null ? null : HttpContext.Profile; }}public HttpRequestBase Request{get { return HttpContext == null ? null : HttpContext.Request; }}public HttpResponseBase Response{get { return HttpContext == null ? null : HttpContext.Response; }}internal RouteCollection RouteCollection{get{if (_routeCollection == null){_routeCollection = RouteTable.Routes;}return _routeCollection;}set { _routeCollection = value; }}public RouteData RouteData{get { return ControllerContext == null ? null : ControllerContext.RouteData; }}public HttpServerUtilityBase Server{get { return HttpContext == null ? null : HttpContext.Server; }}public HttpSessionStateBase Session{get { return HttpContext == null ? null : HttpContext.Session; }}public ITempDataProvider TempDataProvider{get{if (_tempDataProvider == null){_tempDataProvider = CreateTempDataProvider();}return _tempDataProvider;}set { _tempDataProvider = value; }}public UrlHelper Url { get; set; }public IPrincipal User{get { return HttpContext == null ? null : HttpContext.User; }}[SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly", Justification = "This entire type is meant to be mutable.")]public ViewEngineCollection ViewEngineCollection{get { return _viewEngineCollection ?? ViewEngines.Engines; }set { _viewEngineCollection = value; }}[SuppressMessage("Microsoft.Naming", "CA1719:ParameterNamesShouldNotMatchMemberNames", MessageId = "0#", Justification = "'Content' refers to ContentResult type; 'content' refers to ContentResult.Content property.")]protected internal ContentResult Content(string content){return Content(content, null /* contentType */);}[SuppressMessage("Microsoft.Naming", "CA1719:ParameterNamesShouldNotMatchMemberNames", MessageId = "0#", Justification = "'Content' refers to ContentResult type; 'content' refers to ContentResult.Content property.")]protected internal ContentResult Content(string content, string contentType){return Content(content, contentType, null /* contentEncoding */);}[SuppressMessage("Microsoft.Naming", "CA1719:ParameterNamesShouldNotMatchMemberNames", MessageId = "0#", Justification = "'Content' refers to ContentResult type; 'content' refers to ContentResult.Content property.")]protected internal virtual ContentResult Content(string content, string contentType, Encoding contentEncoding){return new ContentResult{Content = content,ContentType = contentType,ContentEncoding = contentEncoding};}protected virtual IActionInvoker CreateActionInvoker(){// Controller supports asynchronous operations by default. // Those factories can be customized in order to create an action invoker for each request.IAsyncActionInvokerFactory asyncActionInvokerFactory = Resolver.GetService<IAsyncActionInvokerFactory>();if (asyncActionInvokerFactory != null){return asyncActionInvokerFactory.CreateInstance();}IActionInvokerFactory actionInvokerFactory = Resolver.GetService<IActionInvokerFactory>();if (actionInvokerFactory != null){return actionInvokerFactory.CreateInstance();}// Note that getting a service from the current cache will return the same instance for every request.return Resolver.GetService<IAsyncActionInvoker>() ??Resolver.GetService<IActionInvoker>() ??new AsyncControllerActionInvoker();}protected virtual ITempDataProvider CreateTempDataProvider(){return Resolver.GetService<ITempDataProvider>() ?? new SessionStateTempDataProvider();}// The default invoker will never match methods defined on the Controller type, so// the Dispose() method is not web-callable.  However, in general, since implicitly-// implemented interface methods are public, they are web-callable unless decorated with// [NonAction].public void Dispose(){Dispose(true /* disposing */);GC.SuppressFinalize(this);}protected virtual void Dispose(bool disposing){}protected override void ExecuteCore(){// If code in this method needs to be updated, please also check the BeginExecuteCore() and// EndExecuteCore() methods of AsyncController to see if that code also must be updated.PossiblyLoadTempData();try{string actionName = GetActionName(RouteData);if (!ActionInvoker.InvokeAction(ControllerContext, actionName)){HandleUnknownAction(actionName);}}finally{PossiblySaveTempData();}}protected internal FileContentResult File(byte[] fileContents, string contentType){return File(fileContents, contentType, null /* fileDownloadName */);}protected internal virtual FileContentResult File(byte[] fileContents, string contentType, string fileDownloadName){return new FileContentResult(fileContents, contentType) { FileDownloadName = fileDownloadName };}protected internal FileStreamResult File(Stream fileStream, string contentType){return File(fileStream, contentType, null /* fileDownloadName */);}protected internal virtual FileStreamResult File(Stream fileStream, string contentType, string fileDownloadName){return new FileStreamResult(fileStream, contentType) { FileDownloadName = fileDownloadName };}protected internal FilePathResult File(string fileName, string contentType){return File(fileName, contentType, null /* fileDownloadName */);}protected internal virtual FilePathResult File(string fileName, string contentType, string fileDownloadName){return new FilePathResult(fileName, contentType) { FileDownloadName = fileDownloadName };}private static string GetActionName(RouteData routeData){Contract.Assert(routeData != null);// If this is an attribute routing match then the 'RouteData' has a list of sub-matches rather than// the traditional controller and action values. When the match is an attribute routing match// we'll pass null to the action selector, and let it choose a sub-match to use.if (routeData.HasDirectRouteMatch()){return null;}else{return routeData.GetRequiredString("action");}}protected virtual void HandleUnknownAction(string actionName){// If this is a direct route we might not yet have an action nameif (String.IsNullOrEmpty(actionName)){throw new HttpException(404, String.Format(CultureInfo.CurrentCulture,MvcResources.Controller_UnknownAction_NoActionName, GetType().FullName));}else{throw new HttpException(404, String.Format(CultureInfo.CurrentCulture,MvcResources.Controller_UnknownAction, actionName, GetType().FullName));}}protected internal HttpNotFoundResult HttpNotFound(){return HttpNotFound(null);}protected internal virtual HttpNotFoundResult HttpNotFound(string statusDescription){return new HttpNotFoundResult(statusDescription);}protected internal virtual JavaScriptResult JavaScript(string script){return new JavaScriptResult { Script = script };}protected internal JsonResult Json(object data){return Json(data, null /* contentType */, null /* contentEncoding */, JsonRequestBehavior.DenyGet);}protected internal JsonResult Json(object data, string contentType){return Json(data, contentType, null /* contentEncoding */, JsonRequestBehavior.DenyGet);}protected internal virtual JsonResult Json(object data, string contentType, Encoding contentEncoding){return Json(data, contentType, contentEncoding, JsonRequestBehavior.DenyGet);}protected internal JsonResult Json(object data, JsonRequestBehavior behavior){return Json(data, null /* contentType */, null /* contentEncoding */, behavior);}protected internal JsonResult Json(object data, string contentType, JsonRequestBehavior behavior){return Json(data, contentType, null /* contentEncoding */, behavior);}protected internal virtual JsonResult Json(object data, string contentType, Encoding contentEncoding, JsonRequestBehavior behavior){return new JsonResult{Data = data,ContentType = contentType,ContentEncoding = contentEncoding,JsonRequestBehavior = behavior};}protected override void Initialize(RequestContext requestContext){base.Initialize(requestContext);Url = new UrlHelper(requestContext);}protected virtual void OnActionExecuting(ActionExecutingContext filterContext){}protected virtual void OnActionExecuted(ActionExecutedContext filterContext){}protected virtual void OnAuthentication(AuthenticationContext filterContext){}protected virtual void OnAuthenticationChallenge(AuthenticationChallengeContext filterContext){}protected virtual void OnAuthorization(AuthorizationContext filterContext){}protected virtual void OnException(ExceptionContext filterContext){}protected virtual void OnResultExecuted(ResultExecutedContext filterContext){}protected virtual void OnResultExecuting(ResultExecutingContext filterContext){}protected internal PartialViewResult PartialView(){return PartialView(null /* viewName */, null /* model */);}protected internal PartialViewResult PartialView(object model){return PartialView(null /* viewName */, model);}protected internal PartialViewResult PartialView(string viewName){return PartialView(viewName, null /* model */);}protected internal virtual PartialViewResult PartialView(string viewName, object model){if (model != null){ViewData.Model = model;}return new PartialViewResult{ViewName = viewName,ViewData = ViewData,TempData = TempData,ViewEngineCollection = ViewEngineCollection};}internal void PossiblyLoadTempData(){if (!ControllerContext.IsChildAction){TempData.Load(ControllerContext, TempDataProvider);}}internal void PossiblySaveTempData(){if (!ControllerContext.IsChildAction){TempData.Save(ControllerContext, TempDataProvider);}}[SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings", MessageId = "0#", Justification = "Response.Redirect() takes its URI as a string parameter.")]protected internal virtual RedirectResult Redirect(string url){if (String.IsNullOrEmpty(url)){throw new ArgumentException(MvcResources.Common_NullOrEmpty, "url");}return new RedirectResult(url);}[SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings", MessageId = "0#", Justification = "Response.RedirectPermanent() takes its URI as a string parameter.")]protected internal virtual RedirectResult RedirectPermanent(string url){if (String.IsNullOrEmpty(url)){throw new ArgumentException(MvcResources.Common_NullOrEmpty, "url");}return new RedirectResult(url, permanent: true);}protected internal RedirectToRouteResult RedirectToAction(string actionName){return RedirectToAction(actionName, (RouteValueDictionary)null);}protected internal RedirectToRouteResult RedirectToAction(string actionName, object routeValues){return RedirectToAction(actionName, TypeHelper.ObjectToDictionary(routeValues));}protected internal RedirectToRouteResult RedirectToAction(string actionName, RouteValueDictionary routeValues){return RedirectToAction(actionName, null /* controllerName */, routeValues);}protected internal RedirectToRouteResult RedirectToAction(string actionName, string controllerName){return RedirectToAction(actionName, controllerName, (RouteValueDictionary)null);}protected internal RedirectToRouteResult RedirectToAction(string actionName, string controllerName, object routeValues){return RedirectToAction(actionName, controllerName, TypeHelper.ObjectToDictionary(routeValues));}protected internal virtual RedirectToRouteResult RedirectToAction(string actionName, string controllerName, RouteValueDictionary routeValues){RouteValueDictionary mergedRouteValues;if (RouteData == null){mergedRouteValues = RouteValuesHelpers.MergeRouteValues(actionName, controllerName, null, routeValues, includeImplicitMvcValues: true);}else{mergedRouteValues = RouteValuesHelpers.MergeRouteValues(actionName, controllerName, RouteData.Values, routeValues, includeImplicitMvcValues: true);}return new RedirectToRouteResult(mergedRouteValues);}protected internal RedirectToRouteResult RedirectToActionPermanent(string actionName){return RedirectToActionPermanent(actionName, (RouteValueDictionary)null);}protected internal RedirectToRouteResult RedirectToActionPermanent(string actionName, object routeValues){return RedirectToActionPermanent(actionName, TypeHelper.ObjectToDictionary(routeValues));}protected internal RedirectToRouteResult RedirectToActionPermanent(string actionName, RouteValueDictionary routeValues){return RedirectToActionPermanent(actionName, null /* controllerName */, routeValues);}protected internal RedirectToRouteResult RedirectToActionPermanent(string actionName, string controllerName){return RedirectToActionPermanent(actionName, controllerName, (RouteValueDictionary)null);}protected internal RedirectToRouteResult RedirectToActionPermanent(string actionName, string controllerName, object routeValues){return RedirectToActionPermanent(actionName, controllerName, TypeHelper.ObjectToDictionary(routeValues));}protected internal virtual RedirectToRouteResult RedirectToActionPermanent(string actionName, string controllerName, RouteValueDictionary routeValues){RouteValueDictionary implicitRouteValues = (RouteData != null) ? RouteData.Values : null;RouteValueDictionary mergedRouteValues =RouteValuesHelpers.MergeRouteValues(actionName, controllerName, implicitRouteValues, routeValues, includeImplicitMvcValues: true);return new RedirectToRouteResult(null, mergedRouteValues, permanent: true);}protected internal RedirectToRouteResult RedirectToRoute(object routeValues){return RedirectToRoute(TypeHelper.ObjectToDictionary(routeValues));}protected internal RedirectToRouteResult RedirectToRoute(RouteValueDictionary routeValues){return RedirectToRoute(null /* routeName */, routeValues);}protected internal RedirectToRouteResult RedirectToRoute(string routeName){return RedirectToRoute(routeName, (RouteValueDictionary)null);}protected internal RedirectToRouteResult RedirectToRoute(string routeName, object routeValues){return RedirectToRoute(routeName, TypeHelper.ObjectToDictionary(routeValues));}protected internal virtual RedirectToRouteResult RedirectToRoute(string routeName, RouteValueDictionary routeValues){return new RedirectToRouteResult(routeName, RouteValuesHelpers.GetRouteValues(routeValues));}protected internal RedirectToRouteResult RedirectToRoutePermanent(object routeValues){return RedirectToRoutePermanent(TypeHelper.ObjectToDictionary(routeValues));}protected internal RedirectToRouteResult RedirectToRoutePermanent(RouteValueDictionary routeValues){return RedirectToRoutePermanent(null /* routeName */, routeValues);}protected internal RedirectToRouteResult RedirectToRoutePermanent(string routeName){return RedirectToRoutePermanent(routeName, (RouteValueDictionary)null);}protected internal RedirectToRouteResult RedirectToRoutePermanent(string routeName, object routeValues){return RedirectToRoutePermanent(routeName, TypeHelper.ObjectToDictionary(routeValues));}protected internal virtual RedirectToRouteResult RedirectToRoutePermanent(string routeName, RouteValueDictionary routeValues){return new RedirectToRouteResult(routeName, RouteValuesHelpers.GetRouteValues(routeValues), permanent: true);}protected internal bool TryUpdateModel<TModel>(TModel model) where TModel : class{return TryUpdateModel(model, null, null, null, ValueProvider);}protected internal bool TryUpdateModel<TModel>(TModel model, string prefix) where TModel : class{return TryUpdateModel(model, prefix, null, null, ValueProvider);}protected internal bool TryUpdateModel<TModel>(TModel model, string[] includeProperties) where TModel : class{return TryUpdateModel(model, null, includeProperties, null, ValueProvider);}protected internal bool TryUpdateModel<TModel>(TModel model, string prefix, string[] includeProperties) where TModel : class{return TryUpdateModel(model, prefix, includeProperties, null, ValueProvider);}protected internal bool TryUpdateModel<TModel>(TModel model, string prefix, string[] includeProperties, string[] excludeProperties) where TModel : class{return TryUpdateModel(model, prefix, includeProperties, excludeProperties, ValueProvider);}protected internal bool TryUpdateModel<TModel>(TModel model, IValueProvider valueProvider) where TModel : class{return TryUpdateModel(model, null, null, null, valueProvider);}protected internal bool TryUpdateModel<TModel>(TModel model, string prefix, IValueProvider valueProvider) where TModel : class{return TryUpdateModel(model, prefix, null, null, valueProvider);}protected internal bool TryUpdateModel<TModel>(TModel model, string[] includeProperties, IValueProvider valueProvider) where TModel : class{return TryUpdateModel(model, null, includeProperties, null, valueProvider);}protected internal bool TryUpdateModel<TModel>(TModel model, string prefix, string[] includeProperties, IValueProvider valueProvider) where TModel : class{return TryUpdateModel(model, prefix, includeProperties, null, valueProvider);}protected internal bool TryUpdateModel<TModel>(TModel model, string prefix, string[] includeProperties, string[] excludeProperties, IValueProvider valueProvider) where TModel : class{if (model == null){throw new ArgumentNullException("model");}if (valueProvider == null){throw new ArgumentNullException("valueProvider");}Predicate<string> propertyFilter = propertyName => BindAttribute.IsPropertyAllowed(propertyName, includeProperties, excludeProperties);IModelBinder binder = Binders.GetBinder(typeof(TModel));ModelBindingContext bindingContext = new ModelBindingContext(){ModelMetadata = ModelMetadataProviders.Current.GetMetadataForType(() => model, typeof(TModel)),ModelName = prefix,ModelState = ModelState,PropertyFilter = propertyFilter,ValueProvider = valueProvider};binder.BindModel(ControllerContext, bindingContext);return ModelState.IsValid;}protected internal bool TryValidateModel(object model){return TryValidateModel(model, null /* prefix */);}protected internal bool TryValidateModel(object model, string prefix){if (model == null){throw new ArgumentNullException("model");}ModelMetadata metadata = ModelMetadataProviders.Current.GetMetadataForType(() => model, model.GetType());foreach (ModelValidationResult validationResult in ModelValidator.GetModelValidator(metadata, ControllerContext).Validate(null)){ModelState.AddModelError(DefaultModelBinder.CreateSubPropertyName(prefix, validationResult.MemberName), validationResult.Message);}return ModelState.IsValid;}protected internal void UpdateModel<TModel>(TModel model) where TModel : class{UpdateModel(model, null, null, null, ValueProvider);}protected internal void UpdateModel<TModel>(TModel model, string prefix) where TModel : class{UpdateModel(model, prefix, null, null, ValueProvider);}protected internal void UpdateModel<TModel>(TModel model, string[] includeProperties) where TModel : class{UpdateModel(model, null, includeProperties, null, ValueProvider);}protected internal void UpdateModel<TModel>(TModel model, string prefix, string[] includeProperties) where TModel : class{UpdateModel(model, prefix, includeProperties, null, ValueProvider);}protected internal void UpdateModel<TModel>(TModel model, string prefix, string[] includeProperties, string[] excludeProperties) where TModel : class{UpdateModel(model, prefix, includeProperties, excludeProperties, ValueProvider);}protected internal void UpdateModel<TModel>(TModel model, IValueProvider valueProvider) where TModel : class{UpdateModel(model, null, null, null, valueProvider);}protected internal void UpdateModel<TModel>(TModel model, string prefix, IValueProvider valueProvider) where TModel : class{UpdateModel(model, prefix, null, null, valueProvider);}protected internal void UpdateModel<TModel>(TModel model, string[] includeProperties, IValueProvider valueProvider) where TModel : class{UpdateModel(model, null, includeProperties, null, valueProvider);}protected internal void UpdateModel<TModel>(TModel model, string prefix, string[] includeProperties, IValueProvider valueProvider) where TModel : class{UpdateModel(model, prefix, includeProperties, null, valueProvider);}protected internal void UpdateModel<TModel>(TModel model, string prefix, string[] includeProperties, string[] excludeProperties, IValueProvider valueProvider) where TModel : class{bool success = TryUpdateModel(model, prefix, includeProperties, excludeProperties, valueProvider);if (!success){string message = String.Format(CultureInfo.CurrentCulture, MvcResources.Controller_UpdateModel_UpdateUnsuccessful,typeof(TModel).FullName);throw new InvalidOperationException(message);}}protected internal void ValidateModel(object model){ValidateModel(model, null /* prefix */);}protected internal void ValidateModel(object model, string prefix){if (!TryValidateModel(model, prefix)){throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture,MvcResources.Controller_Validate_ValidationFailed,model.GetType().FullName));}}protected internal ViewResult View(){return View(viewName: null, masterName: null, model: null);}protected internal ViewResult View(object model){return View(null /* viewName */, null /* masterName */, model);}protected internal ViewResult View(string viewName){return View(viewName, masterName: null, model: null);}protected internal ViewResult View(string viewName, string masterName){return View(viewName, masterName, null /* model */);}protected internal ViewResult View(string viewName, object model){return View(viewName, null /* masterName */, model);}protected internal virtual ViewResult View(string viewName, string masterName, object model){if (model != null){ViewData.Model = model;}return new ViewResult{ViewName = viewName,MasterName = masterName,ViewData = ViewData,TempData = TempData,ViewEngineCollection = ViewEngineCollection};}[SuppressMessage("Microsoft.Naming", "CA1719:ParameterNamesShouldNotMatchMemberNames", MessageId = "0#", Justification = "The method name 'View' is a convenient shorthand for 'CreateViewResult'.")]protected internal ViewResult View(IView view){return View(view, null /* model */);}[SuppressMessage("Microsoft.Naming", "CA1719:ParameterNamesShouldNotMatchMemberNames", MessageId = "0#", Justification = "The method name 'View' is a convenient shorthand for 'CreateViewResult'.")]protected internal virtual ViewResult View(IView view, object model){if (model != null){ViewData.Model = model;}return new ViewResult{View = view,ViewData = ViewData,TempData = TempData};}IAsyncResult IAsyncController.BeginExecute(RequestContext requestContext, AsyncCallback callback, object state){return BeginExecute(requestContext, callback, state);}void IAsyncController.EndExecute(IAsyncResult asyncResult){EndExecute(asyncResult);}protected virtual IAsyncResult BeginExecute(RequestContext requestContext, AsyncCallback callback, object state){if (DisableAsyncSupport){// For backwards compat, we can disallow async support and just chain to the sync Execute() function.Action action = () =>{Execute(requestContext);};return AsyncResultWrapper.BeginSynchronous(callback, state, action, _executeTag);}else{if (requestContext == null){throw new ArgumentNullException("requestContext");}// Support Asynchronous behavior. // Execute/ExecuteCore are no longer called.VerifyExecuteCalledOnce();Initialize(requestContext);// Ensure delegates continue to use the C# Compiler static delegate caching optimization.BeginInvokeDelegate<Controller> beginDelegate = (AsyncCallback asyncCallback, object callbackState, Controller controller) =>{return controller.BeginExecuteCore(asyncCallback, callbackState);};EndInvokeVoidDelegate<Controller> endDelegate = (IAsyncResult asyncResult, Controller controller) =>{controller.EndExecuteCore(asyncResult);};return AsyncResultWrapper.Begin(callback, state, beginDelegate, endDelegate, this, _executeTag);}}protected virtual IAsyncResult BeginExecuteCore(AsyncCallback callback, object state){// If code in this method needs to be updated, please also check the ExecuteCore() method// of Controller to see if that code also must be updated.PossiblyLoadTempData();try{string actionName = GetActionName(RouteData);IActionInvoker invoker = ActionInvoker;IAsyncActionInvoker asyncInvoker = invoker as IAsyncActionInvoker;if (asyncInvoker != null){// asynchronous invocation// Ensure delegates continue to use the C# Compiler static delegate caching optimization.BeginInvokeDelegate<ExecuteCoreState> beginDelegate = delegate(AsyncCallback asyncCallback, object asyncState, ExecuteCoreState innerState){return innerState.AsyncInvoker.BeginInvokeAction(innerState.Controller.ControllerContext, innerState.ActionName, asyncCallback, asyncState);};EndInvokeVoidDelegate<ExecuteCoreState> endDelegate = delegate(IAsyncResult asyncResult, ExecuteCoreState innerState){if (!innerState.AsyncInvoker.EndInvokeAction(asyncResult)){innerState.Controller.HandleUnknownAction(innerState.ActionName);}};ExecuteCoreState executeState = new ExecuteCoreState() { Controller = this, AsyncInvoker = asyncInvoker, ActionName = actionName };return AsyncResultWrapper.Begin(callback, state, beginDelegate, endDelegate, executeState, _executeCoreTag);}else{// synchronous invocationAction action = () =>{if (!invoker.InvokeAction(ControllerContext, actionName)){HandleUnknownAction(actionName);}};return AsyncResultWrapper.BeginSynchronous(callback, state, action, _executeCoreTag);}}catch{PossiblySaveTempData();throw;}}protected virtual void EndExecute(IAsyncResult asyncResult){AsyncResultWrapper.End(asyncResult, _executeTag);}protected virtual void EndExecuteCore(IAsyncResult asyncResult){// If code in this method needs to be updated, please also check the ExecuteCore() method// of Controller to see if that code also must be updated.try{AsyncResultWrapper.End(asyncResult, _executeCoreTag);}finally{PossiblySaveTempData();}}#region IActionFilter Membersvoid IActionFilter.OnActionExecuting(ActionExecutingContext filterContext){OnActionExecuting(filterContext);}void IActionFilter.OnActionExecuted(ActionExecutedContext filterContext){OnActionExecuted(filterContext);}#endregion#region IAuthenticationFilter Membersvoid IAuthenticationFilter.OnAuthentication(AuthenticationContext filterContext){OnAuthentication(filterContext);}void IAuthenticationFilter.OnAuthenticationChallenge(AuthenticationChallengeContext filterContext){OnAuthenticationChallenge(filterContext);}#endregion#region IAuthorizationFilter Membersvoid IAuthorizationFilter.OnAuthorization(AuthorizationContext filterContext){OnAuthorization(filterContext);}#endregion#region IExceptionFilter Membersvoid IExceptionFilter.OnException(ExceptionContext filterContext){OnException(filterContext);}#endregion#region IResultFilter Membersvoid IResultFilter.OnResultExecuting(ResultExecutingContext filterContext){OnResultExecuting(filterContext);}void IResultFilter.OnResultExecuted(ResultExecutedContext filterContext){OnResultExecuted(filterContext);}#endregion// Keep as value type to avoid allocatingprivate struct ExecuteCoreState{internal IAsyncActionInvoker AsyncInvoker;internal Controller Controller;internal string ActionName;}
}

}

简单的了解一下MVC相关推荐

  1. python可视化界面编程 pycharm_pycharm开发一个简单界面和通用mvc模板(操作方法图解)...

    文章首先使用pycharm的 PyQt5 Designer 做一个简单的界面,然后引入所谓的"mvc框架". 一.设计登录界面 下面开始第一个话题,使用pycharm的 PyQt5 ...

  2. [导入]ASP.NET MVC框架开发系列课程(2):一个简单的ASP.NET MVC应用程序.zip(13.70 MB)...

    讲座内容: 使用ASP.NET MVC框架进行开发与ASP.NET WebForms截然不同.本次课程将通过官方的示例程序简单了解一下ASP.NET MVC应用程序的结构与特点. 课程讲师: 赵劼 M ...

  3. 一个非常简单的 ASP.NET MVC 示例:长轮询(又叫:反向 AJAX,英文名:Comet)实现...

    关于 长轮询(又叫:反向 AJAX,英文名:Comet)的介绍,请查看:反向Ajax,第1部分:Comet介绍 下面是代码实现: UI: <p><input type="b ...

  4. 实现简单的注解型MVC框架 —— 低配SpringMVC

    文章目录 目标 最终效果展示 基本步骤 1. 解析控制器类: 2. 解析处理函数: 3. 解析处理函数变量名: 4. 监听TCP连接: 5. 实现路由函数: 知识点总结 目标 与SpringMvc定义 ...

  5. JavaWeb学习总结(四十九)——简单模拟Sping MVC

    在Spring MVC中,将一个普通的java类标注上Controller注解之后,再将类中的方法使用RequestMapping注解标注,那么这个普通的java类就够处理Web请求,示例代码如下: ...

  6. python mvc框架_MVC其实很简单(Django框架)

    Django框架MVC其实很简单 让我们来研究一个简单的例子,通过该实例,你可以分辨出,通过Web框架来实现的功能与之前的方式有何不同. 下面就是通过使用Django来完成以上功能的例子: 首先,我们 ...

  7. MVC简单学习以及浅显理解

    以下仅为个人简单浅显理解: MVC来处理Web问题: 路由定位:(如何快速精确地定位请求,分层管理请求?) 此处使用视图Controller的思想来达到分离不同层下的请求,对于同一层下的请求放入一个控 ...

  8. (转自:孤傲苍狼)简单模拟Sping MVC

    2019独角兽企业重金招聘Python工程师标准>>> 转自: http://www.cnblogs.com/xdp-gacl/p/4101727.html 在Spring MVC中 ...

  9. MVC导出Excel之NPOI简单使用(一)

    一,NPOI是个啥 NPOI可以对Word或Excel文档等进行读写操作.NPOI 是 POI 项目的 .NET 版本.POI是一个开源的Java读写Excel.WORD等微软OLE2组件文档的项目. ...

最新文章

  1. Ngrok实现远程控制和操作树莓派(Raspbian系统)
  2. python四个带 key 参数的函数(max、min、map、filter)
  3. 后台开发经典书籍--linux性能优化
  4. 过 DNF TP 驱动保护(一)
  5. C# 这些年来受欢迎的特性
  6. 一些很有意思的JS现象
  7. LeetCode-39. 组合总和 I
  8. 最大比例(压轴题 )
  9. 这5条职场心机,句句真实,引发深思
  10. 万份销量,五星好评!这门Python神作刷爆朋友圈!
  11. 特征提取之——Haar特征
  12. LOJ6504 「雅礼集训 2018 Day5」Convex 凸包、莫队
  13. 说说命令提示符:tcping命令、tcp协议和ping命令
  14. QT tablewidget设置表头
  15. 自定义控件学习笔记(三)Paint详解
  16. 台式计算机显示不了无线网络,我是台式电脑,插上无线网卡怎么我的链接里不显示无线...
  17. CSS实现兼容浏览器的文字阴影效果
  18. Android关于微博发表微博时@好友后删除@的好友的功能实现
  19. Linux7 下Hadoop集群用户管理方案之五 安装Hadoop集群遇到的坑
  20. java 线程的插队运行_java笔记--线程的插队行为

热门文章

  1. python将日期分隔成单独的年月日时分列
  2. 中华数据库与运维安全大会全程解析
  3. 2019年‘泰迪杯’数据分析职业技能大赛A题——个人代码分享
  4. iptables 应用
  5. 【2017今日头条】头条校招(JAVA)
  6. printf(%d%d%d%d\n, a,b,c);
  7. python 空集_Python——集(set)
  8. 如何编写一个简易网络爬虫
  9. 中国电压力锅市场盈利前景与未来发展趋势研究报告2022版
  10. 检查凭证录入模板的核算项目研发项目是否录入