mirror of https://github.com/abpframework/abp.git
6 changed files with 27 additions and 36 deletions
@ -1,4 +1,5 @@ |
|||||
<div class="my-simple-widget"> |
@model DashboardDemo.Web.Pages.Components.MySimpleWidget.MySimpleWidgetViewModel |
||||
|
<div class="my-simple-widget"> |
||||
<h2>My Simple Widget</h2> |
<h2>My Simple Widget</h2> |
||||
<p>This is a simple widget!</p> |
<p>Hello <strong>@Model.Name</strong>! This is a simple widget!</p> |
||||
</div> |
</div> |
||||
@ -1,36 +1,18 @@ |
|||||
using System.Collections.Generic; |
using Microsoft.AspNetCore.Mvc; |
||||
using Microsoft.AspNetCore.Mvc; |
|
||||
using Volo.Abp.AspNetCore.Mvc; |
using Volo.Abp.AspNetCore.Mvc; |
||||
using Volo.Abp.AspNetCore.Mvc.UI.Bundling; |
|
||||
using Volo.Abp.AspNetCore.Mvc.UI.Widgets; |
using Volo.Abp.AspNetCore.Mvc.UI.Widgets; |
||||
|
|
||||
namespace DashboardDemo.Web.Pages.Components.MySimpleWidget |
namespace DashboardDemo.Web.Pages.Components.MySimpleWidget |
||||
{ |
{ |
||||
[Widget( |
[Widget( |
||||
StyleTypes = new[] { typeof(MySimpleWidgetStyleBundleContributor) }, |
StyleFiles = new[] { "/Pages/Components/MySimpleWidget/Default.css" }, |
||||
ScriptTypes = new[] { typeof(MySimpleWidgetScriptBundleContributor) } |
ScriptFiles = new[] { "/Pages/Components/MySimpleWidget/Default.js" } |
||||
)] |
)] |
||||
public class MySimpleWidgetViewComponent : AbpViewComponent |
public class MySimpleWidgetViewComponent : AbpViewComponent |
||||
{ |
{ |
||||
public IViewComponentResult Invoke() |
public IViewComponentResult Invoke(string name) |
||||
{ |
{ |
||||
return View("~/Pages/Components/MySimpleWidget/Default.cshtml"); |
return View(new MySimpleWidgetViewModel { Name = name }); |
||||
} |
|
||||
} |
|
||||
|
|
||||
public class MySimpleWidgetStyleBundleContributor : BundleContributor |
|
||||
{ |
|
||||
public override void ConfigureBundle(BundleConfigurationContext context) |
|
||||
{ |
|
||||
context.Files.AddIfNotContains("/Pages/Components/MySimpleWidget/Default.css"); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
public class MySimpleWidgetScriptBundleContributor : BundleContributor |
|
||||
{ |
|
||||
public override void ConfigureBundle(BundleConfigurationContext context) |
|
||||
{ |
|
||||
context.Files.AddIfNotContains("/Pages/Components/MySimpleWidget/Default.js"); |
|
||||
} |
} |
||||
} |
} |
||||
} |
} |
||||
@ -0,0 +1,7 @@ |
|||||
|
namespace DashboardDemo.Web.Pages.Components.MySimpleWidget |
||||
|
{ |
||||
|
public class MySimpleWidgetViewModel |
||||
|
{ |
||||
|
public string Name { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -1,9 +1,10 @@ |
|||||
@page |
@page |
||||
@using DashboardDemo.Web.Pages.Components.MySimpleWidget |
|
||||
@model DashboardDemo.Web.Pages.MyWidgetsModel |
@model DashboardDemo.Web.Pages.MyWidgetsModel |
||||
|
|
||||
@await Component.InvokeAsync(typeof(MySimpleWidgetViewComponent)) |
@* Example usage by widget name *@ |
||||
<hr /> |
@await Component.InvokeAsync("MySimpleWidget", new { name = "John" }) |
||||
@await Component.InvokeAsync("MySimpleWidget") |
|
||||
<hr /> |
<hr /> |
||||
<vc:my-custom-name-widget></vc:my-custom-name-widget> |
|
||||
|
@* Example usage by widget type *@ |
||||
|
@await Component.InvokeAsync("MySimpleWidget", new { name = "Mete" }) |
||||
Loading…
Reference in new issue