To clarify more of the architecture and how I ended up solving it. I have the following projects / assemblies:
- Business Objects
- VB XML De/Serialization library
- ASP.NET MVC Project
The VB XML assembly handles serializing the business objects dealing with only the business (#1) model. So i would output an XElement something like this:
<invoice>
<invoiceId>1234</invoiceId>
<customer>Hudsucker Industries</customer>
<otherBusinessData>etc, etc</otherBusinessData>
</invoice>
The problem arises that I am using jqGrid and I need to add elements to each invoice to certain actions so I need something like:
<invoice>
<actionHtml><![CDATA[ ...some HTML such as links... ]]></actionHtml>
<invoiceId>1234</invoiceId>
<customer>Hudsucker Industries</customer>
<otherBusinessData>etc, etc</otherBusinessData>
</invoice>
I got it to work but I had to generate all the actionHtml in the controller which is obviously not a good separation of concerns and I lost all my HtmlHelper methods and such. So how I ended up solving it the 'correct' way is:
- Using a WebForms view (I use brail views for my pages) [so I can use the ContentType page attribute to set it to XML].
- Pass the collection of my raw business objects as the model data.
- Loop the model collection, building the actonHtml element for each invoice in the view (hence getting my HtmlHelper methods and such)
- To output the actual business elements I can simply invoke my VB XML library and do a:
invoice.ToXml().Elements().ToString()
and I am good.
To further make this more reusable I created a jqGrid master page that has all the record counts and such in content areas so I can just pass that information in on the actual pages and just worry about outputting the element data.