diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Widgets/Volo/Abp/AspNetCore/Mvc/UI/Widgets/WidgetAttribute.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Widgets/Volo/Abp/AspNetCore/Mvc/UI/Widgets/WidgetAttribute.cs index d8e4c94dfc..24f6077b95 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Widgets/Volo/Abp/AspNetCore/Mvc/UI/Widgets/WidgetAttribute.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Widgets/Volo/Abp/AspNetCore/Mvc/UI/Widgets/WidgetAttribute.cs @@ -9,13 +9,13 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Widgets public class WidgetAttribute : Attribute { [CanBeNull] - public string[] StyleSrcs { get; set; } + public string[] StyleFiles { get; set; } [CanBeNull] public Type[] StyleTypes { get; set; } [CanBeNull] - public string[] ScriptSrcs { get; set; } + public string[] ScriptFiles { get; set; } [CanBeNull] public Type[] ScriptTypes { get; set; } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Widgets/Volo/Abp/AspNetCore/Mvc/UI/Widgets/WidgetDefinition.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Widgets/Volo/Abp/AspNetCore/Mvc/UI/Widgets/WidgetDefinition.cs index fc8f447b4f..b8581e499f 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Widgets/Volo/Abp/AspNetCore/Mvc/UI/Widgets/WidgetDefinition.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Widgets/Volo/Abp/AspNetCore/Mvc/UI/Widgets/WidgetDefinition.cs @@ -68,9 +68,9 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Widgets { var styles = new List(); - if (!widgetAttribute.StyleSrcs.IsNullOrEmpty()) + if (!widgetAttribute.StyleFiles.IsNullOrEmpty()) { - styles.AddRange(widgetAttribute.StyleSrcs.Select(src => new WidgetResourceItem(src))); + styles.AddRange(widgetAttribute.StyleFiles.Select(src => new WidgetResourceItem(src))); } if (!widgetAttribute.StyleTypes.IsNullOrEmpty()) @@ -85,9 +85,9 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Widgets { var scripts = new List(); - if (!widgetAttribute.ScriptSrcs.IsNullOrEmpty()) + if (!widgetAttribute.ScriptFiles.IsNullOrEmpty()) { - scripts.AddRange(widgetAttribute.ScriptSrcs.Select(src => new WidgetResourceItem(src))); + scripts.AddRange(widgetAttribute.ScriptFiles.Select(src => new WidgetResourceItem(src))); } if (!widgetAttribute.ScriptTypes.IsNullOrEmpty()) diff --git a/samples/DashboardDemo/src/DashboardDemo.Web/Pages/Components/MySimpleWidget/Default.cshtml b/samples/DashboardDemo/src/DashboardDemo.Web/Pages/Components/MySimpleWidget/Default.cshtml index eb00022157..2f4323bf89 100644 --- a/samples/DashboardDemo/src/DashboardDemo.Web/Pages/Components/MySimpleWidget/Default.cshtml +++ b/samples/DashboardDemo/src/DashboardDemo.Web/Pages/Components/MySimpleWidget/Default.cshtml @@ -1,4 +1,5 @@ -
+@model DashboardDemo.Web.Pages.Components.MySimpleWidget.MySimpleWidgetViewModel +

My Simple Widget

-

This is a simple widget!

+

Hello @Model.Name! This is a simple widget!

\ No newline at end of file diff --git a/samples/DashboardDemo/src/DashboardDemo.Web/Pages/Components/MySimpleWidget/MySimpleWidgetViewComponent.cs b/samples/DashboardDemo/src/DashboardDemo.Web/Pages/Components/MySimpleWidget/MySimpleWidgetViewComponent.cs index 94e3e13fc2..89b1ccfe00 100644 --- a/samples/DashboardDemo/src/DashboardDemo.Web/Pages/Components/MySimpleWidget/MySimpleWidgetViewComponent.cs +++ b/samples/DashboardDemo/src/DashboardDemo.Web/Pages/Components/MySimpleWidget/MySimpleWidgetViewComponent.cs @@ -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.UI.Bundling; using Volo.Abp.AspNetCore.Mvc.UI.Widgets; namespace DashboardDemo.Web.Pages.Components.MySimpleWidget { [Widget( - StyleTypes = new[] { typeof(MySimpleWidgetStyleBundleContributor) }, - ScriptTypes = new[] { typeof(MySimpleWidgetScriptBundleContributor) } + StyleFiles = new[] { "/Pages/Components/MySimpleWidget/Default.css" }, + ScriptFiles = new[] { "/Pages/Components/MySimpleWidget/Default.js" } )] public class MySimpleWidgetViewComponent : AbpViewComponent { - public IViewComponentResult Invoke() + public IViewComponentResult Invoke(string name) { - return View("~/Pages/Components/MySimpleWidget/Default.cshtml"); - } - } - - 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"); + return View(new MySimpleWidgetViewModel { Name = name }); } } } \ No newline at end of file diff --git a/samples/DashboardDemo/src/DashboardDemo.Web/Pages/Components/MySimpleWidget/MySimpleWidgetViewModel.cs b/samples/DashboardDemo/src/DashboardDemo.Web/Pages/Components/MySimpleWidget/MySimpleWidgetViewModel.cs new file mode 100644 index 0000000000..f4fd1b0a95 --- /dev/null +++ b/samples/DashboardDemo/src/DashboardDemo.Web/Pages/Components/MySimpleWidget/MySimpleWidgetViewModel.cs @@ -0,0 +1,7 @@ +namespace DashboardDemo.Web.Pages.Components.MySimpleWidget +{ + public class MySimpleWidgetViewModel + { + public string Name { get; set; } + } +} \ No newline at end of file diff --git a/samples/DashboardDemo/src/DashboardDemo.Web/Pages/MyWidgets.cshtml b/samples/DashboardDemo/src/DashboardDemo.Web/Pages/MyWidgets.cshtml index 59163b499b..c05038c2c2 100644 --- a/samples/DashboardDemo/src/DashboardDemo.Web/Pages/MyWidgets.cshtml +++ b/samples/DashboardDemo/src/DashboardDemo.Web/Pages/MyWidgets.cshtml @@ -1,9 +1,10 @@ @page -@using DashboardDemo.Web.Pages.Components.MySimpleWidget @model DashboardDemo.Web.Pages.MyWidgetsModel -@await Component.InvokeAsync(typeof(MySimpleWidgetViewComponent)) -
-@await Component.InvokeAsync("MySimpleWidget") +@* Example usage by widget name *@ +@await Component.InvokeAsync("MySimpleWidget", new { name = "John" }) +
- + +@* Example usage by widget type *@ +@await Component.InvokeAsync("MySimpleWidget", new { name = "Mete" }) \ No newline at end of file