Thursday, July 4, 2013

MVC 3 Razor. Partial View validation is not working

Everytime you perform an AJAX call and substitute some part of your DOM with partial HTML contents returned by the controller action you need to reparse the client side unobtrusive validation rules. So in your AJAX success callbacks when after you call the .html() method to refresh the DOM you need to parse:
 function reparseForm(form) {  
       var $form = $(form);  
       $form.removeData('validator');  
       $form.removeData('unobtrusiveValidation');  
       $.validator.unobtrusive.parse(form);  
     }  

Tuesday, June 11, 2013

Tracing and Message Logging (svclog)

 <configuration>  
  <system.serviceModel>  
   <diagnostics>  
    <!-- Enable Message Logging here. -->  
    <!-- log all messages received or sent at the transport or service model levels >  
    <messageLogging logEntireMessage="true"  
            maxMessagesToLog="300"  
            logMessagesAtServiceLevel="true"  
            logMalformedMessages="true"  
            logMessagesAtTransportLevel="true" />  
   </diagnostics>  
  </system.serviceModel>  
  <system.diagnostics>  
   <sources>  
    <source name="System.ServiceModel" switchValue="Information,ActivityTracing"  
     propagateActivity="true">  
     <listeners>  
      <add name="xml" />  
     </listeners>  
    </source>  
    <source name="System.ServiceModel.MessageLogging">  
     <listeners>  
      <add name="xml" />  
     </listeners>  
    </source>  
   </sources>  
   <sharedListeners>  
    <add initializeData="C:\logs\TracingAndLogging-client.svclog" type="System.Diagnostics.XmlWriterTraceListener"  
     name="xml" />  
   </sharedListeners>  
   <trace autoflush="true" />  
  </system.diagnostics>  
 </configuration>  

Tuesday, May 14, 2013

Javascript: Get all function of an object

 
function getMethods(obj) {
 var result = [];
 for (var id in obj) {
  try {
   if (typeof(obj[id]) == "function") {
    result.push(id + ": " + obj[id].toString());
    //result.push(id);
   }
  } catch (err) {
   result.push(id + ": inaccessible");
  }
 }
 return result;
}

Monday, April 8, 2013

Override Jquery client validation on date format

 $(function () {  
   // Replace the builtin US date validation with UK date validation  
   $.validator.addMethod(  
     "date",  
     function (value, element) {  
       var bits = value.match(/([0-9]+)/gi), str;  
       if (!bits)  
         return this.optional(element) || false;  
       str = bits[1] + '/' + bits[0] + '/' + bits[2];  
       return this.optional(element) || !/Invalid|NaN/.test(new Date(str));  
     },  
     "Please enter a date in the format dd/mm/yyyy"  
   );  
 });  

Jquery Unobtrusive validation on hidden field

 <script type="text/javascript">   
 $(function () {   
 var form = $('#[formID]);   
 form.data('validator').settings.ignore = ''; // default is ":hidden".   
 });   
 </script>  

Thursday, March 7, 2013

Change the object graph or increase the MaxItemsInObjectGraph quota. '. Please see InnerException for more details.

Original Article

When you start with WCF, you will certainly need to adjust the limits of the service. By default they are kind of low. So in my case we did. Especially the maxrecievedmessagesize.

Setting up the service, configuring you’re limits and start to use. Sounds really great and simple. But sometimes when you are working with development data and start doing stress tests, you will encounter even more limits. One of these will generate this really nice error:

The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:GetCountriesResult. The InnerException message was 'Maximum number of items that can be serialized or deserialized in an object graph is '65536'. Change the object graph or increase the MaxItemsInObjectGraph quota. '. Please see InnerException for more details.

What this really means is that the number of objects send through the wire is higher than the default limit or the limit you have specified. To send more large number of records (objects) over the wire you’ll need to adjust the following:

On the server (raise the maxitemsinobjectgraph):

1
2
3
4
5
6
7
8
<behaviors>
      <serviceBehaviors>
        <behavior>
          
          <dataContractSerializer maxItemsInObjectGraph="10000000"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>


On the client (raise the maxitemsinobjectgraph for the clients endpoint behavior):

1
2
3
4
5
6
7
<behaviors>
      <endpointBehaviors>
        <behavior >
          <dataContractSerializer maxItemsInObjectGraph="10000000"/>
        </behavior>
      </endpointBehaviors>
    </behaviors>


The maximum size of the maxItemsInObjectGraph is: 2147483646.

Now you can get those long lists of data and sent it over the wire. Although I strongly believe you should reconsider when a lot of these exceptions occur and split up data in chunks or rethink the way the data is shown to the user.