Archive for the ‘Uncategorized’ Category

I ran into an issue using NHibernate + domain objects with the Syncfusion grid.
I am using an auto incremented [generated identity] integer primary key that NHibernate expects to be null when creating a new item.

With the syncfusion grid, the primary key is a required field on the “add new” form/dialog by default.
To avoid the requirement of supplying a value in the “add new” form, you can hide the parent div of the primary key input item by using the “OnActionSuccess” client event.

        .ClientSideEvents(events =>

Then the javascript function to hide the field from validation…
In this case, the field mapping is “Id”.

            function HideOnAdd(sender, args) {
                if (args.RequestType == 'AddNew') {
                    var gridObj = $('#GenericListGridEditDialog');
                    gridObj.find('#Id').parent().css('display', 'none');

If you are using a different edit method, the name of the form or dialog could be a different format.

(using MVC4 beta)

In some cases it is not easy to alter the header values to negotiate the content type returned from WEBAPI.

There is a QueryStringMapper object you can add to the Media Type Formatter objects that allow you to use a query string to negotiate the content format.

In the example below,¬† I am adding a query string parameter ‘format’ to the mapping. When ‘format’ == ‘xml’, the content type is ‘text/xml’ and the XmlMediaTypeFormatter is used.

I run this in the ‘Application_Start’ method of the Global.asax¬†

            foreach (var item in GlobalConfiguration.Configuration.Formatters)
                if (typeof(XmlMediaTypeFormatter) == item.GetType())
                    item.AddQueryStringMapping("format", "xml", "text/xml");

Example api call – http://localhost/api/foo?format=xml