Write your first widget
1.Create DNA2 Appliaction
2.Add Widget Action
Right click the “Controllers” folder in project and named “WidgetDemoController”
Add a Action method named “HelloWorld” then add “DNA.Mvc.DynamicUI.WidgetAttribute” on the top the Action method – developers just need to specified the WidgetAttribute class on top of the target action that the Action will become a Widget. Developer just uses WidgetAttribute class and PropertyAttribute class to define a Widget. The Widget development is same as Action development in Mvc.
1: namespace DNA2Application1.Controllers
2: {
3: public class MyController : Controller
4: {
5: [Widget("HelloWord",Category="Demo")]
6: public ActionResult HelloWord()
7: {
8: return View();
9: }
10: }
11: }
3.Add Widget View
Add View for this Action.
DNA2 Offers the Widget extension method to render the widget conent.Now we just only output the “Hello world” text in widget body.
Use Content method to contain the widget ouput.
1: <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
2: <%
3: Ajax.Dna().Widget()
4: .Content(widget => {
5: %>
6: <div>Hello worlddiv>
7: <%
8: })
9: .Render();
10: %>
Pass “F5” build and run the project.
4.Generate Widget Package
Go to “SiteTools/Console/Widgets” , Click the “Discover” button to generate the Widget definition file.
Click “Register” button to add the “HelloWorld” widget to widget register catelog that the users could be found the “HelloWorld” widget in “WidgetExplorer”
5.Add the Widget to Page
Go to home page and select “SiteTools/Design this page” to enter the page design mode.Then click “SiteTools/Add Content” to open the WidgetExplorer.
After preivew the HelloWord widget select “zone1” and click “Add”
Now your first widget has added on your runtime page now.
-
-
Lần đọc(1362)
-
Permalink