asp.net-core-viewcomponent

Where should I include a script for a view component?

只愿长相守 提交于 2019-12-21 12:08:38
问题 I have tried adding a section script inside a view component's view. @section scripts { <script src="~/somepath" asp-append-version="true"></script> } I also have the Render Section in the shared layout @RenderSection("scripts", required: false) When used in partial views and elsewhere in the project the script loads fine. However when in a View Component the script does not load. I suppose I could include the script in the section tag of every view that calls the component. I feel this does

What's the difference between HttpContext.RequestAborted and CancellationToken parameter?

亡梦爱人 提交于 2019-12-20 01:45:15
问题 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 CancellationToken parameter I could also chain the tokens Option 1 looks like this: public class AmazingMessageViewComponent : ViewComponent { public async Task<IViewComponentResult> InvokeAsync(string text, int wait) { //uses request aborted await Task.Delay

ASP.NET Core layout page multiple sidebar menu

半世苍凉 提交于 2019-12-13 01:35:14
问题 So here's the problem, user can select one of six links, something like this after he select specific link for example Link 1 he should be redirected to home page with sidebar menu looking like this: If he select for example Link 2 his menu should look like this: Anyway, i got no idea how to achieve this since my menu is located inside _Layout.cshtml, could View Component feature help me with this issue?? 回答1: I found solution myself using viewComponent feature. First of all i had to

ViewComponent and InvokeAsync method

ぃ、小莉子 提交于 2019-12-12 11:13:00
问题 In the following method I'm getting the warning : This async method lacks 'await' operators and will run synchronously . Where can I use await in this mehod? Note : This method is returning a simple static View without interacting with a Database etc. public class TestViewComponent : ViewComponent { public async Task<IViewComponentResult> InvokeAsync() { return View(); } } 回答1: Since you have no asynchronous work to do, you could remove the async qualifier and just return Task.FromResult :

Can you use a ViewComponent in a Blazor layout

我只是一个虾纸丫 提交于 2019-12-11 04:53:33
问题 Just trying Blazor for the first time. With the default blazor template, I added a ViewComponent call to the MainLayout.cshtml: @await Component.InvokeAsync("HeaderComponent") Intellisense shows await can only be used in an async method. I tried the same in a Blazor view - same result. I use the component in an MVC app in the layout (i use vc:header-component there). So I'm not sure if this is possible, or just a current Blazor or VS2019 limitation. 回答1: No, you can't use ViewComponent in

Confirm delete modal/dialog with Twitter bootstrap not working

喜你入骨 提交于 2019-12-07 18:29:41
问题 A ViewComponent in my ASP.NET Core 1.1 project on VS2015 has a confirm delete modal/dialog with Twitter bootstrap as shown below. But when a user clicks on the Delete button to confirm a delete it does not trigger the jquery function shown below. The modal/dialog pops up fine but when I click on delete button with id= DeleteBtnID inside the modal/dialog I would expect it to popup the `alert('Test') but that is not happening. Question: What I may be missing? No errors are shown in Chrome's

Confirm delete modal/dialog with Twitter bootstrap not working

 ̄綄美尐妖づ 提交于 2019-12-06 14:16:01
A ViewComponent in my ASP.NET Core 1.1 project on VS2015 has a confirm delete modal/dialog with Twitter bootstrap as shown below. But when a user clicks on the Delete button to confirm a delete it does not trigger the jquery function shown below. The modal/dialog pops up fine but when I click on delete button with id= DeleteBtnID inside the modal/dialog I would expect it to popup the `alert('Test') but that is not happening. Question: What I may be missing? No errors are shown in Chrome's Developer Tool. View that calls ViewComponent : @model MyProj.Models.TestModel some html .... .... <div id

ViewComponents are not async

走远了吗. 提交于 2019-12-05 06:40:54
问题 I am trying to use the ViewComponents.InvokeAsync() feature, but somehow this is not async at all. It is waiting for the component code to render. http://docs.asp.net/en/latest/mvc/views/view-components.html My code is very much similar to the one explained in above example. I am using the layout page which comes when you create new application in MVC 6. I thought that ViewComponent.InvokeAsync() method will render asynchronously with respect to the main page. But it does not. In order to

ViewComponent in external assembly cannot be found

非 Y 不嫁゛ 提交于 2019-12-04 12:55:36
I am using the latest VS.2017 updates and templates for an MVC .NET Core web application. I decided I wanted ViewComponents in an external assembly since I read several posts that indicated it was not possible without odd tricks. I have my main web application and then I created a .NET Framework class library named MySite.Components which is the "external assembly". In it I installed the ViewFeatures NuGet. I created my View component CSHTML in its /Views/Shared/Components/GoogleAdsense/Default.cshtml. I noticed that my CSPROJ already has the GoogleAdSense as an embedded resource: <ItemGroup>

Is it possible to call ViewComponent from custom TagHelper?

和自甴很熟 提交于 2019-12-04 10:07:51
问题 I'm writing a custom TagHelper and want to render a ViewComponent inside it. Something similar to what vc:xyz tag helper does, but in a more controlled way, so that I can determine at runtime which ViewComponent to render. Is it possible? 回答1: In order to do that, you need to inject IViewComponentHelper into your TagHelper, contextualize it and then use it to render any ViewComponent depending on your application logic. Here is a quick illustration: [HtmlTargetElement("widget", Attributes =