[CLOSED] How to display html from the model

  1. #1

    [CLOSED] How to display html from the model

    Hi,

    we are developing a solution to create customer invoices. The invoice is generated as an HTML document. We wish to display the HTML to the user with a button for approval.

    The model has a string field which contains the full html code of the invoice.

    public partial class InvoiceOutput
        {
            public short OutputId { get; set; }
            public int Quantity { get; set; }
            public decimal Price { get; set; }
            public string Html { get; set; }
            public System.DateTime DateCreated { get; set; }
        }
    We have tried

    X.FormPanelFor(s => s.Html)
    However, we can't get the HTML to display.

    What is the correct/best way to display a formatted HTML document?

    Thanks
    Ian
  2. #2
    How about setting the .Html property of a Panel?
    Geoffrey McGill
    Founder
  3. #3
    Hi Geoffrey,

    can you provide an example how to set the Html property of the panel from the (MVC) model. I've tried to access it from the store, without success.

    Thanks in advance
    Ian
    Last edited by ibradley; Dec 04, 2019 at 8:45 PM.
  4. #4
    Assuming your model is an InvoiceOutput class with a Html string property, you then just provide the Html reference to the .Html() property. There's really not much:

    @model InvoiceOutput
    
    @(
        Html.X().Panel()
            .Html(Model.Html)
    )
    Hope this helps!
  5. #5

    That worked!

    Thanks, that worked you can close this thread.

    However, what is the difference between using
    s=>s.html
    and
    model.html
    ?
  6. #6
    Hello @ibradley!

    How would it guess you want property s.html to go within the grid's Html property if s.html is but a string? It should at least have a .Html property in order to be mapped, something to indicate where the string should go.

    I didn't test as we already have it working in a way you could accept, but if you're really curious about it, you could try changing the InvoiceOutput.Html property from string into an object (class or anonymous) containing another Html property, or InvoiceOutput.Html.Html.

    Doesn't it make sense? Hope this helps!
    Fabrício Murta
    Developer & Support Expert
  7. #7
    Hi Fabricio,

    sorry my question wasn't very clear.

    In the cshtml view we have always used s=>s.field to map to the model, i.e. X.ComboBoxFor(s => s.Currency), but I see we can also use Model.field, i.e X.ComboBoxFor(Model.Currency).

    What are the differences between s=>s.field and Model.field and what is best practice?

    Thanks
    Ian
  8. #8
    Hello Ian!

    There's no "best practice" among them, you're just using different ways to initialize the component. Different <component>For() components have different possible ways of filling them up with data or set up.

    The issue in your case is that you were just providing a string to the FormPanelFor expecting it to assume the string should imply its Html config; which is not the case. An expression provided as parameter to a FormPanelFor() is interpreted as an object dictating its inner fields, as you can see in the feature example in our Examples Explorer sample: Models > FormPanelFor.

    If you check the example above you'll see that the object it maps into the fields (within the FormPanelForModel.cs source file) has some special attributes (Field and UIHint) to instruct Ext.NET how to deal with some possible fields in the built page.

    It just happens how the interpreter was built does not treat a provided string (instead of an object) as the expression should be treated as the component's Html property/config, as this is a somewhat unlikely setting to be used in that component.

    In other words, if you want to set a specific config of a component, not always <component>For would cover it. Then you can just direct the desired value straight to the setting you want it to receive, as we suggested for your initial inquire.

    Hope this helps!
    Fabrício Murta
    Developer & Support Expert

Similar Threads

  1. Error in display data create by html Editor
    By chienthang159 in forum 1.x Help
    Replies: 1
    Last Post: Jul 03, 2014, 8:26 AM
  2. Replies: 0
    Last Post: Jul 31, 2013, 3:23 AM
  3. Replies: 1
    Last Post: Jul 30, 2013, 3:36 PM
  4. [CLOSED] making text area to display html formated text
    By SymSure in forum 2.x Legacy Premium Help
    Replies: 1
    Last Post: Sep 19, 2012, 5:07 PM
  5. [CLOSED] Html editor display
    By speedstepmem2 in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Nov 10, 2009, 12:10 PM

Posting Permissions