Skip to content

DevExpress-Examples/asp-net-mvc-round-panel-set-content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Round Panel for ASP.NET MVC - How to define control content

The SetContent method allows you to define the content of DevExpress MVC extensions. This example demonstrates how to use these method overloads to define RoundPanel content in the following ways:

  • Call the SetContent(String content) method overload to specify the content as a string. This overload is intended for scenarios where it is necessary to render simple HTML content (specified directly as a parameter).
    settings.SetContent(@"<table border=\"1\"><tr><td>RoundPanel Content Here</td></tr></table>");
    
  • Call the SetContent(Action contentMethod) method overload to add a DevExpress MVC Extension in the panel content.
    settings.SetContent(() => {
        Html.DevExpress().Label(lbl => {
            lbl.Name = "lbl";
            lbl.Text = "DevExpress Label - Some Text";
        }).Render();
    });
    
  • Call the ViewContext.Writer.Write method to combine different syntax constructions (raw HTML tags, action methods, built-in HtmlHelper methods, DevExpress MVC Extensions) into a text stream and pass it to the SetContent(String content) method overload.
    settings.SetContent(() => {
        //Raw HTML
        ViewContext.Writer.Write("<table border=\"1\"><tr><td>Content From Raw <b>HTML</b> Table Here...</td></tr></table>");
        ViewContext.Writer.Write("<br/>");
    
        //Action Method
        Html.RenderAction("SeparateAction");
        ViewContext.Writer.Write("<br/>");
        ViewContext.Writer.Write("<br/>");
    
        //Partial View with Html.BeginForm
        Html.RenderPartial("SeparatePartialView");
        ViewContext.Writer.Write("<br/>");
        ViewContext.Writer.Write("<br/>");
    
        //Html Helper
        ViewContext.Writer.Write(Html.TextBox("txtName").ToHtmlString());
        ViewContext.Writer.Write("<br/>");
        ViewContext.Writer.Write("<br/>");
        
        //Conditional
        ViewContext.Writer.Write("Content From Conditional Rendering Block:");
        ViewContext.Writer.Write("<br/>");
        bool condition = DateTime.Now.Year == 2014;
        if(condition) {
            ViewContext.Writer.Write("<b>Condition Passed</b>");
        } else {
            ViewContext.Writer.Write("<b>Condition Failed</b>");
        }
        ViewContext.Writer.Write("<br/>");
        ViewContext.Writer.Write("<br/>");
        
        //DevExpress MVC Extensions
        Html.DevExpress().Label(lbl => {
            lbl.Name = "lbl";
            lbl.Text = "Content From DevExpress Label Here...";
        }).Render();
    });
    

You can use these approaches for every DevExpress MVC Extension that suppors the SetContent or SetNestedContent method.

It is also possible to handle Set{ElementName}TemplateContent methods to define template content.

Files to Review

Documentation