GithubHelp home page GithubHelp logo

aspnet / mvc Goto Github PK

View Code? Open in Web Editor NEW
5.6K 803.0 2.1K 70.43 MB

[Archived] ASP.NET Core MVC is a model view controller framework for building dynamic web sites with clean separation of concerns, including the merged MVC, Web API, and Web Pages w/ Razor. Project moved to https://github.com/aspnet/AspNetCore

License: Apache License 2.0

Shell 0.06% JavaScript 0.03% HTML 2.70% C# 97.08% CSS 0.01% Batchfile 0.01% PowerShell 0.05% F# 0.01% Groovy 0.01% Lua 0.03%
aspnet-product

mvc's Introduction

ASP.NET Core MVC [Archived]

This GitHub project has been archived. Ongoing development on this project can be found in https://github.com/aspnet/AspNetCore.

Note: For ASP.NET MVC 5.x, Web API 2.x, and Web Pages 3.x (not ASP.NET Core), see https://github.com/aspnet/AspNetWebStack

ASP.NET Core MVC gives you a powerful, patterns-based way to build dynamic websites that enables a clean separation of concerns and gives you full control over markup for enjoyable, agile development. ASP.NET Core MVC includes many features that enable fast, TDD-friendly development for creating sophisticated applications that use the latest web standards.

ASP.NET Core MVC includes support for building web pages and HTTP services in a single aligned framework that can be hosted in IIS or self-hosted in your own process.

See the ASP.NET Core MVC documentation.

Related community projects:

This project is part of ASP.NET Core. You can find samples, documentation and getting started instructions for ASP.NET Core at the AspNetCore repo.

Building from source

To run a complete build on command line only, execute build.cmd or build.sh without arguments. See developer documentation for more details.

mvc's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mvc's Issues

Reintroduce resources

We need to reintroduce a bunch of resources that were left out as part of the migration. These resources today exist as either inline strings or as commented out strings (e.g. "MvcResources.SomeResourceName"). These need to be referenced via a resx file.

Expose Model State information about current request

I need access to model state information to check if the posted data to my action is valid or not. But currently there is no way to access model state information from within a controller's action.
Provide a way to access model state from within an action & also provide a way to access it from within the action filters too.

Revisit HtmlHelper.AnonymousObjectToHtmlAttributes implementation

HtmlHelper.AnonymousObjectToHtmlAttributes() and the RouteValueDictionary(object) constructor handle properties of the given object differently. In particular HtmlHelper.AnonymousObjectToHtmlAttributes() will include static properties in the dictionary. new properties may also confuse this method.

In the old world, HtmlHelper.AnonymousObjectToHtmlAttributes() skips a check to see if the passed object is already an IDictionary<string, object> (not needed due to specific overloads for dictionaries) and adds underscore to dash mapping of the property names. Neither of these differences exist in WebFx -- but probably should.

[extensibility] Revisit DefaultHtmlRenderer.RenderInput() interface

The DefaultHtmlRenderer.RenderInput() method under discussion in PR #50 is difficult to override and useful only for the limited selection of verbs the InputType enumeration covers. Though a DefaultHtmlRenderer subclass could override this method and take some action (e.g. output an HTML comment or trace) prior to calling the base implementation, that override can't do much other than string manipulation with the return value.
Possible ways to go:

  1. pass a string for the inputType parameter
  2. return a single TagBuilder rather than the current HtmlString; call RenderInput() twice from RenderCheckbox() to handle the additional hidden element
  3. move all or most of the input-specific handling up into methods such as RenderTextBox()

A tilda (~) in the src value leads to razor compilation exception

For example have something like this:

Stack trace:
Microsoft.AspNet.Mvc.Razor.CompilationFailedException: Compilation Failed:(19,168): error CS0103: The name 'Href' does not exist in the current context
at Microsoft.AspNet.Mvc.Razor.CompilationResult.get_CompiledType()
at Microsoft.AspNet.Mvc.Razor.CompilerCache.d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNet.Mvc.Razor.VirtualPathViewFactory.d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at Microsoft.AspNet.Mvc.Razor.RazorViewEngine.d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNet.Mvc.ViewResult.d__1.MoveNext()

Two test failures when using CoreCLR

@pranavkm as we discussed, pull request #100 leaves two test failures under CoreCLR. These are both in ModelValidationNodeTest and I didn't change that file -- code appears to be fully supported in both CoreCLR and .NET 4.5. But I see the following, perhaps indicating validation is skipping a step or losing some logging messages in CoreCLR.

Microsoft.AspNet.Mvc.ModelBinding.ModelValidationNodeTest.Validate_Ordering [FAIL]
  Assert.Equal() Failure
  Expected: String[] { "In OnValidating()", "In LoggingValidatonAttribute.IsValid()", "In IValidatableObject.Validate()", "In OnValidated()" }
  Actual:   String[] { "In OnValidating()", "In LoggingValidatonAttribute.IsValid()", "In OnValidated()" }
  Stack Trace:
    at Microsoft.AspNet.Mvc.ModelBinding.ModelValidationNodeTest.Validate_Ordering()
    in C:\dd\k\WebFx.new\test\Microsoft.AspNet.Mvc.ModelBinding.Test\Validation\ModelValidationNodeTest.cs:line 145
   Microsoft.AspNet.Mvc.ModelBinding.ModelValidationNodeTest.Validate_SkipsRemainingValidationIfModelStateIsInvalid [FAIL]
 Assert.Equal() Failure
  Expected: String[] { "In OnValidating()", "In IValidatableObject.Validate()", "In OnValidated()" }
  Actual:   String[] { "In OnValidating()", "In OnValidated()" }
  Stack Trace:
    at Microsoft.AspNet.Mvc.ModelBinding.ModelValidationNodeTest.Validate_SkipsRemainingValidationIfModelStateIsInvalid()
    in C:\dd\k\WebFx.new\test\Microsoft.AspNet.Mvc.ModelBinding.Test\Validation\ModelValidationNodeTest.cs:line 168

Determine if we'd be able to consume either an AppName or root namespace

For view generations, we'd prefer generating namespaces based off of a root namespace e.g. namespace MyApp.Views.Home. Today we use the directory name of the app root. We might need this in other generated content such as resx files. It would be nice if we could have an API (Configuration?) that provides us this root namespace value.

Should Action Selector return ActionContext

Right now ActionSelector creates ActionContexts to get access to model binding, and then returns an ActionDescriptor. The calling code immediately constructs an ActionContext.

Consider returning ActionContext here. This would allow us to share value providers without any specialized caching code.

ModelMetadata.IsReadOnly needs to be updated to account for absent ReadOnlyAttribute

Related to [https://github.com//issues/88].

We used to depend on TypeDescriptors for property discovery in the past. A behavior of TypeDescriptor is that it appends the ReadOnlyAttribute on properties that are readonly \ have private setters.

It would be useful to revisit this as part of the model metadata data flow clean up and see if we can do it in a better way than the hack I'm planning on adding now.

Model binding fails to bind the value on POST from jQuery

I notice the model binding fails to bind value when I make a POST request from jQuery. On doing a POST with jQuery I see the content type is automatically set with a charset like below.

Content-Type: application/x-www-form-urlencoded; charset=UTF-8

When I remove the charset=UTF-8 and make a request it works, but with this charset it fails.

ControllerActionInvoker or ReflectedActionInvoker

From @loudej

his family of classes should probably be named ControllerActionInvoker, ControllerActionInvokerProvider, ControllerActionDescriptorProvider, ControllerActionDescriptor, etc.

I say that because the thing that distinguishes them is they comprehend the controller classes. The fact they use reflection is more an implementation detail, and most invokers would use reflection of some sort.

IViewEngine API needs some design

Right now IViewEngine takes an action descriptor as a parameter. It's typed as object because our layering doesn't allow this to be ActionDescriptor

Layering issues aside, this is a very high degree of coupling and should be looked it. This is pretty similar to the legacy MVC contract (ControllerContext), so it's easy to see how we got here.

    public interface IViewEngine
    {
        Task<ViewEngineResult> FindView(object actionContext, string viewName);
    }

Model binding fails when the model has a generic list

My model looks like the following:

public class Suggestion
    {
        public int Id { get; set; }

        public string Title { get; set; }

        public string Description { get; set; }

        public IList<Comment> Comments { get; set; }
    }

Request content-type is application/x-www-form-urlencoded

Exception:
System.Exception: TODO: unable to locate suitable constructor for Microsoft.AspNet.Mvc.ModelBinding.IModelBinder
at Microsoft.AspNet.DependencyInjection.TypeActivator.CreateInstance(Type instanceType, Object[] parameters)
at Microsoft.AspNet.DependencyInjection.TypeActivatorExtensions.CreateInstance[T](ITypeActivator activator, Object[] parameters)
at Microsoft.AspNet.Mvc.ModelBinding.GenericModelBinder.BindModel(ModelBindingContext bindingContext)
at Microsoft.AspNet.Mvc.ModelBinding.CompositeModelBinder.TryBind(ModelBindingContext bindingContext)
at Microsoft.AspNet.Mvc.ModelBinding.CompositeModelBinder.BindModel(ModelBindingContext bindingContext)
at Microsoft.AspNet.Mvc.ModelBinding.ComplexModelDtoModelBinder.BindModel(ModelBindingContext bindingContext)
at Microsoft.AspNet.Mvc.ModelBinding.CompositeModelBinder.TryBind(ModelBindingContext bindingContext)
at Microsoft.AspNet.Mvc.ModelBinding.CompositeModelBinder.BindModel(ModelBindingContext bindingContext)
at Microsoft.AspNet.Mvc.ModelBinding.MutableObjectModelBinder.CreateAndPopulateDto(ModelBindingContext bindingContext, IEnumerable`1 propertyMetadatas)
at Microsoft.AspNet.Mvc.ModelBinding.MutableObjectModelBinder.BindModel(ModelBindingContext bindingContext)
at Microsoft.AspNet.Mvc.ModelBinding.CompositeModelBinder.TryBind(ModelBindingContext bindingContext)
at Microsoft.AspNet.Mvc.ModelBinding.CompositeModelBinder.BindModel(ModelBindingContext bindingContext)
at Microsoft.AspNet.Mvc.ReflectedActionInvoker.<GetParameterValues>d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at Microsoft.AspNet.Mvc.ReflectedActionInvoker.<InvokeActionAsync>d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNet.Mvc.MvcApplication.<RouteAsync>d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNet.Routing.Template.TemplateRoute.<RouteAsync>d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNet.Routing.RouteCollection.<RouteAsync>d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNet.Abstractions.RouterMiddleware.<Invoke>d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNet.Loader.IIS.KlrHttpApplication.<ProcessRequestAsyncImpl>d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNet.Loader.IIS.HttpApplicationBase.<InvokeProcessRequestAsyncImpl>d__1.MoveNext()</

Revisit RazorView<dynamic> default base type

Currently the MvcRazorCodeParser determines which TModel to use in RazorView<TModel> exclusively using the @model directive. If a view contains no such directive, the calling MvcRazorHost falls back to RazorView<dynamic>. This ignores TModel information available when compiling calls to Controller.View<TModel>(... TModel model).

Suggest passing TModel through to the appropriate methods in MvcRazorHost where it may provide a better default than dynamic. TModel may have other uses there as well.

Side note: Unconditionally creating ViewData<TModel> in the Controller class (what Controller.View<TModel>() does at this moment) is also incorrect because the @model directive parsed later may specify a different type.

Should ClientValidationRuleFactory be exposed to users?

In the old world, HtmlHelper had an internal property named ClientValidationRuleFactory. We probably don't want to maintain it as internal but also likely want to make something available to subclasses choosing to override GetValidationAttributes(), assuming we decide to make that method virtual.
his property was frequently used in unit tests to mock validation errors or other validation results during tests. Since our validation abstractions are changing significantly, we should keep this use case in mind when completing the client-side validation implementation in the new world.

when a request is not handled, 404 should be thrown instead of 200

I had following route.
routes.MapRoute(
"{controller}",
new { controller = "Home" });

I called GET on http://localhost:5001/bugs/1.

I got back 200 status code with response

HTTP/1.1 200 OK
Transfer-Encoding: chunked
Server: Microsoft-IIS/8.0
X-SourceFiles: =?UTF-8?B?RzpcU2FtcGxlc1xBcHAxXFNhbXBsZXNcQXBwMS5XZWJcYnVnc1wx?=
X-Powered-By: ASP.NET
Date: Tue, 11 Mar 2014 17:18:55 GMT

1a
No one handled the request
0

Expected to see 404 since the request was not handled

[implementation] Revisit FormContext storage in HttpContext

Each request gets a default FormContext instance for use when rendering inputs and providing their validation attributes outside @Html.BeginForm() ... @Html.EndForm(). Likely this default instance should either be shared beyond the lifetime of the containing ViewContext (e.g. stored in the HttpContext) or lazy-initialized.
Further we probably will not need to store explicitly-created FormContext instances in the HttpContext once we get ViewContext flowing and updating correctly.
Look at this issue after we've got @Html.Partial(), child actions, and the templated helpers (@Html.Display[For[Model]]() and @Html.Editor[For[Model]]()) in place.

[implementation] Remove System.Reflection.Compatibility-like helpers from `TypeExtensions`

Current TypeExtensions class(es) contain(s) extension methods such as IsAssignableFrom() which may be ambiguous in any consuming class that uses System.Reflection. To create the ambiguity, someone would only need to add the System.Reflection.Compatibility package to the project's dependencies. In addition we should all be learning about the new Reflection APIs.

Should migrate existing code to use GetTypeInfo() directly. (Another possibility would be to always rely on the System.Reflection.Compatibility package but that is not the preferred direction. Finally could use helpers with unambiguous names -- but such extension methods just hide the new APIs and slow learning.)

Support missing `@Html.AttributeEncode()` methods

In the old world, Encode() and AttributeEncode() have become more-and-more alike. According to @GrabYourPitchforks, this was intentional as doing a less complete encoding in attributes has caused problems in the past.
In the new world, the current PR for HTML helpers (#50) includes AttributeEncode() methods which just delegate to Encode(). This supports copy-and-paste scenarios for existing MVC users. But we may want to clean out the "extra" methods.

Having ViewBag.Title in the beginning of a cshtml file results in compiler error on CoreClr + Helios

On Helios + CoreClr:
@{
ViewBag.Title = "Home Page";
}

Have this in the beginning of a cshtml file. Razor throws this error. The same works fine on Helios + net45.

Microsoft.AspNet.Mvc.Razor.CompilationFailedException: Compilation Failed:Views\Home\Index.cshtml(3,5): error CS0656: Missing compiler required member 'Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create'
at Microsoft.AspNet.Mvc.Razor.CompilationResult.get_CompiledType()
at Microsoft.AspNet.Mvc.Razor.CompilerCache.d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNet.Mvc.Razor.VirtualPathViewFactory.d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at Microsoft.AspNet.Mvc.Razor.RazorViewEngine.d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNet.Mvc.ViewResult.d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

Consider moving RequestContext to MVC.Core

RequestContext is defined in the model binding project for some reason. Currently only the IValueProviderFactory interface in that project uses it.

We can move IVPF to MVC.Core without too much mixing of concerns. A VPF is an mvc-specific integration point, so it should live with general mvc code.

Alternative here is to create a contracts project where some of these more common types live.

ReadOnlyAttribute does not exist in CoreCLR

Right now, we've a placeholder ReadOnlyAttribute in the ModelBinding assembly. ReadOnlyAttribute was previously located in System.dll (not System.ComponentModel.DataAnnotations) and is no longer present in CoreCLR.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.