Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why was @Html.Action removed? #343

Closed
glen-84 opened this issue Mar 1, 2015 · 5 comments
Closed

Why was @Html.Action removed? #343

glen-84 opened this issue Mar 1, 2015 · 5 comments

Comments

@glen-84
Copy link
Contributor

glen-84 commented Mar 1, 2015

I was just reading this blog post and I noticed the following:

Subcontrollers – the Html.Action() helper — are not included in the current beta of MVC 6.

Why was it removed? Because of issues with async?

Imagine that I want to render a box in the right column, containing a paged list of items (example [Tournaments box]). I can do the initial rendering with a view component, but view components are not routable (as far as I know), which means that I can't load that view directly (for AJAX paging).

Is there some other way of accomplishing this? The only option that I can think of is to use a view component to render the initial template, and then have it request JSON data for subsequent pages, as opposed to HTML. This is less flexible though, and a bit messy (since you would need a JSON endpoint in addition to the view component).

Related:
https://aspnetwebstack.codeplex.com/workitem/601
http://aspnet.uservoice.com/forums/41201-asp-net-mvc/suggestions/3233329-support-asynchronous-child-actions

@Eilon
Copy link
Member

Eilon commented Mar 1, 2015

Hi there,

The Html.Action helper was for working with Child Actions, which were removed when we started MVC 6. We removed them because we came up with what we felt was an overall better feature called View Components. Here's an article that shows how to use them: http://www.asp.net/vnext/overview/aspnet-vnext/vc

You can certainly do an AJAX-based approach, but if you want to do it all on the server, View Components are the way to go. The concepts of Child Actions and View Components are fairly similar in many ways, so it should generally be fairly easy to migrate from one to the other.

Thanks,
Eilon

@Eilon Eilon closed this as completed Mar 1, 2015
@Eilon
Copy link
Member

Eilon commented Mar 1, 2015

Oh, and you can do async View Components too, so that's a 👍 for View Components 😄

@glen-84
Copy link
Contributor Author

glen-84 commented Mar 2, 2015

@Eilon,

View components allow you to do an initial rendering, but since they aren't "routable" (they have no URL to address them), they cannot be rendered individually.

Imagine a "widget" that you want to render initially in a "parent" view. You then want to allow users to "refresh" that widget, or load subsequent pages of the widget. This is not possible with view components, as they can only be run as part of a parent view.

An example could be a comment system displayed under a blog post. The URL to the blog post might be something like "/blog/posts/1" and the URL to the comments might be "/blog/posts/1/comments". You would use Html.Action to load the initial comments, and then load URLs like "/blog/posts/1/comments?page=2" with AJAX.

  • With view components, subsequent rendering is not possible.
  • With controller actions, initial rendering is no longer possible.

I guess the only other option is the one that I mentioned in my initial post (VC + JSON endpoint). This means that it's impossible to have the template rendered on the server-side (after the initial rendering), unless you duplicated the template and had a controller action returning HTML in addition to the VC, but that's not good at all.

@Eilon
Copy link
Member

Eilon commented Mar 3, 2015

True, that is indeed a difference between the two. To individually render a View Component you could certainly "wrap" it in another action that has a view to render just the view component. In my view that is a better pattern because it makes it much clearer to the developers which actions are routable/callable and which things are just view components. A problem with the Child Actions feature was that two different concepts were conflated into one. This resulted in a Leaky Abstraction because many things didn't work in Child Actions, such as authorization filters, redirects, etc. In MVC 6 we decided to make it 100% clear that view components are different from MVC actions. I do agree, however, that in some cases it's more code to achieve the same result, but in my view it's better code.

@glen-84
Copy link
Contributor Author

glen-84 commented Mar 4, 2015

Thanks Eilon.

natemcmaster pushed a commit that referenced this issue Nov 20, 2018
This change tries to avoid looking up the TEMP directory for most reads of
the form data. We'll now only hit the disk when necessary.
@ghost ghost locked as resolved and limited conversation to collaborators Dec 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants