Questions tagged [asp.net-core-viewcomponent]

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.

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…
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…
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:…
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…
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…
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…
11
votes
2 answers

Custom ViewComponent with asp-for as parameter

I want wrap this: