ASP.NET Core MVC feature similar to partial views, with much more powerful functionality and reusable rendering logic that's too complex for a partial view.
Questions tagged [asp.net-core-viewcomponent]
177 questions
21
votes
1 answer
Viewcomponent alternative for ajax refresh
I have a viewcomponent that contains some reusable business logic that embed in various pages. This has been working fine. However, I now have a requirement to refresh the viewcomponent using ajax.
Is there any way to accomplish this? From what…
![](../../users/profiles/306894.webp)
czuroski
- 4,166
- 8
- 47
- 84
20
votes
3 answers
ASP.NET MVC 6: view components in a separate assembly
I'd like to define view components (which are new in ASP.NET MVC 6) in a separate assembly from the MVC 6 web startup project so that I can reuse them in multiple web projects. A sample solution might look like this:
BookStore.Components (houses…
![](../../users/profiles/188740.webp)
Johnny Oshika
- 45,610
- 33
- 151
- 234
13
votes
5 answers
Where should I include a script for a view component?
I have tried adding a section script inside a view component's view.
@section scripts {
}
I also have the Render Section in the shared layout
@RenderSection("scripts", required:…
![](../../users/profiles/7172409.webp)
Oliver Orchard
- 462
- 1
- 4
- 15
13
votes
1 answer
Can I reload an asp 5/MVC 6 View Component via ajax?
I am playing around with MVC 6 and have a grid of Users that are currently registered to my site. Above the gird, I have built a View Component for the search/filter functionality. It is invoked via
@Component.Invoke("UserSearchBar")
One of the…
![](../../users/profiles/4166524.webp)
Joshua Engelbrecht
- 185
- 2
- 8
12
votes
1 answer
Where should my Javascript go for View Components?
I'm getting used to view components in MVC 6, and I asked a similar question a few years ago about partial views. If I build a view component encapsulating a common use-case that requires its own Javascript, where do I put that Javascript? I know…
![](../../users/profiles/27457.webp)
AJ.
- 15,284
- 19
- 85
- 143
11
votes
2 answers
How to unit test ViewComponent.Invoke()?
In ViewComponent object, HttpContext and User are read-only properties.
How to unit test such a component?
I'm using the MSTest Freamwork.
The follow properties are used in my code
Cookie
Session
User(System.Security.Principal)
public…
![](../../users/profiles/7771913.webp)
HeroWong
- 341
- 2
- 12
11
votes
2 answers
11
votes
3 answers
ViewComponent tag helpers not working
I have updated my asp.net core web application from 1.0.1 to 1.1.0, but tag helpers for my viewcomponents are not working:
it outputs the tag. It works using old syntax: @await…
![](../../users/profiles/475727.webp)
Liero
- 19,054
- 16
- 100
- 195
11
votes
2 answers
Submit form and do controller action from ViewComponent in ASP.NET Core
I want to add ListItems from a form in a ViewComponent in an ASP.NET 5, Mvc core application.
The component view (Views\Shared\Components\AddListItem\Default.cshtml):
@model ShoppingList.Models.ListItem
9
votes
1 answer
What's the difference between HttpContext.RequestAborted and CancellationToken parameter?
I'm trying to create an async view component for ASP.NET Core 2.0. It will do an action that should be cancelled when the user navigates away from the page. I've got the following options:
Using the HttpContext.RequestAborted
Using a…
![](../../users/profiles/201482.webp)
Kees C. Bakker
- 28,682
- 24
- 104
- 188
9
votes
1 answer
How to return JSON from a View Component?
I am trying to move controller logic into a view component class, but the controller only returns JSON, for a client side widget that is the UI of my view component. This is the core controller code where the problem is:
public IActionResult…
![](../../users/profiles/8741.webp)
ProfK
- 44,292
- 106
- 358
- 713
9
votes
1 answer
TagHelper for ASPNET CORE ViewComponent not working
I'm in the process of getting to grips with ASPNET CORE [version 1.1, using VS2017 Community, version 15.1 (26403.3)]I've created a working ViewComponent called UserDetails (abbreviated below):
namespace…
![](../../users/profiles/1384601.webp)
Tim Morrison
- 198
- 1
- 7
8
votes
2 answers
asp.net Core View Component executed but markup not rendered
I have an ASP.NET Core 1.1 web application developed with VS.2017 and I decided to put some of the view functionality in a view component (have done others before).
This view component fetches a Dictionary collection of permissions associated to a…
![](../../users/profiles/1200667.webp)
Lord of Scripts
- 3,420
- 5
- 35
- 59
8
votes
1 answer
ViewComponent with optional parameters
I am creating a set of View Components that represent filters on different views. They work great so far, but I don't understand this behavior I am experiencing.
If I use declare two InvokeAsync:
public async Task…
![](../../users/profiles/2141621.webp)
Camilo Terevinto
- 26,697
- 6
- 67
- 99
8
votes
2 answers
How share ViewData between ViewComponent in Asp.net core
I have two ViewComponent and i want use ViewData or other technic for share some data between and then use this data in main view, but this is not the way, and ViewData per ViewComponent is null when rich to if condition for both…
![](../../users/profiles/1890983.webp)
Mohammad Akbari
- 3,809
- 5
- 31
- 58