[CLOSED] Razor formatting and using ui definitions in regular c# code modules

  1. #1

    [CLOSED] Razor formatting and using ui definitions in regular c# code modules

    I absolutely despise how razor has issues with huge blocks of Ext.Net nested declarations. It is so confusing that I literally don't want to edit code anymore.

    So, I am wondering if there are any recommendations for declaration all the ui in regular c# code modules in static methods like:
    var grid = new GridPanel();
                grid.Region = Region.North;
                grid.ID = "JobGrid";
                grid.SelectionModel.Add(new RowSelectionModel() { Mode = SelectionMode.Single });
                grid.Listeners.BeforeEdit.Fn = "beforeJobEdit";
                grid.Title = "Jobs";
                grid.Layout = LayoutType.Border.ToString();
    and then just do ToScript() in a one liner inside of razor.

    Is this viable? Am I missing any functionality like this? This way my formatting will be just the way it normally is inside c# code modules, correct?

    One quick thing I noticed is that grid.Layout is a string but in razor you set it to LayoutType.Border. Is there a comprehensive code sample that covers issues like this?

    Wouldn't I also be able to more easily reuse code modules by adding an instantiated class as a child to another?

    Thanks
    Last edited by Daniil; Feb 27, 2015 at 1:00 PM. Reason: Please use [CODE] tags, [CLOSED]
  2. #2
    One additional issue I am running in to is how to initialize API inline and how to translate Url.Action:
    public static AjaxProxy GetJobProxy()
            {
                var proxy = new AjaxProxy()
                {             
                                             NoCache=false,
                                             AppendAction=false,
                                             API = //it only has a public setter???
                                             new CRUDUrls()
                                             {
                                                 Read = "/api/admin/jobs"
                                                 //a.Update = Url.Action("UpdateJob");
                                                 //a.Create = Url.Action("CreateJob");
                                             }
            }
    Last edited by Daniil; Feb 20, 2015 at 4:01 PM. Reason: Please use [CODE] tags
  3. #3
    Hi @t316,

    Please use [CODE] tags wrapping all the code in the future (did it this time for you, no need to thank;)). You might want to review this document.
    Forum Guidelines For Posting New Topics

    Also please keep one issue per thread. So, in this thread let's discuss a problem with formatting Razor code.

    Yes, unfortunately, auto formatting (Ctrl+K+D) doesn't handle it well. It is also a problem for me as well. Though, at the moment I am used to format manually quite fast when I code by myself. But when I copy/paste some code samples from forum threads, it is a problem. Often the code is formatted very poorly and it is quite hard to read.

    I doubt we have any options to improve formatting in Visual Studio.

    As for your consideration to use a regular C# way of creating control, you could try the following. Hope that helps.

    Example
    @{
        var X = Html.X(); 
    }
    
    <!DOCTYPE html>
    <html>
    <head>
        <title>Ext.Net.MVC v3 Example</title>  
    </head>
    <body>
        @X.ResourceManager()
        
        @{
            var button = new Ext.Net.Button
            {
                Text = "Click me",
                Handler = "alert('Clicked')"
            }; 
        }
    
        @button.ToBuilder()
    </body>
    </html>

Similar Threads

  1. [CLOSED] EXT.NET MVC Razor view Code Formatting tool
    By matrixwebtech in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: Feb 20, 2018, 7:11 PM
  2. More code formatting options
    By geoffrey.mcgill in forum Open Discussions
    Replies: 11
    Last Post: Feb 08, 2015, 7:18 PM
  3. Desktop modules - User Controls in MVC3 RAZOR
    By millenovanta in forum 2.x Help
    Replies: 8
    Last Post: Dec 09, 2012, 6:44 PM
  4. Replies: 0
    Last Post: Jun 15, 2012, 9:06 AM
  5. [CLOSED] How add Modules in Web Desktop
    By hrc in forum 2.x Legacy Premium Help
    Replies: 1
    Last Post: Apr 30, 2012, 12:31 PM

Posting Permissions