PDA

View Full Version : [CLOSED] How to display html from the model



ibradley
Dec 04, 2019, 9:08 AM
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

geoffrey.mcgill
Dec 04, 2019, 9:32 PM
How about setting the .Html property of a Panel?

ibradley
Dec 04, 2019, 9:38 PM
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

fabricio.murta
Dec 05, 2019, 4:10 PM
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!

ibradley
Dec 18, 2019, 9:06 AM
Thanks, that worked you can close this thread.

However, what is the difference between using
s=>s.html and
model.html?

fabricio.murta
Dec 18, 2019, 7:30 PM
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!

ibradley
Dec 18, 2019, 8:31 PM
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

fabricio.murta
Dec 20, 2019, 8:29 PM
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 (https://mvc5.ext.net/#/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!