ThinkGeo.com    |     Documentation    |     Premium Support

Map argument is always null in Controller Action method

Hello!



I have this Action method in my controller:



[MapActionFilter]

public string EditShape(Map map, GeoCollection args)

{

 //…

}



and on the view I have an Ajax call like this:


Map1.ajaxCallAction("Map""EditShape"null, editShapeCallback);





The method is being called by the map argument is always null. Any idea what might be wrong here?



Thanks

Karsten


I found that this problem was caused by this attribute that I had assigned to my Controller class: 
  
 [SessionState(SessionStateBehavior.ReadOnly)] 
  
 It was copied accidently from a different controller class where I in fact need to set this attribute to just pretend (!) that session state is read only in order to allow concurrent async ajax calls, while my class is responsible for dealing with synchronization issues. When I remove the above attribute, the map argument is assigned okay. 
  
 Does the MapActionFilterAttribute implementation (or elsewhere) evaluate the session state in a way what setting this attribute would stop the map argument to become assigned? Can I circumvent this somehow? For the moment it’s okay for me to remove the SessionState attribute, but in the future this may become a problem for me. 
  
 Thanks 
 Karsten

Hi Karsten,



The MVC edition will save the map and some related states to Session, then we can maintain map on the server side. So if set the session state behavior to ReadOnly, there will be some issues. And if we don’t save session successfully, we will not process the arguments in MapActionFilter, that’s reason why argument is always null. 
If this controller must to be assigned as ReadOnly session in the future. we may help you provide some workaround to use the map without session, but the Map and aguments from AjaxCall will be null as well. You need to maintain the map object by youself, maybe using Model  for server and client.



Regards,

Kevin

Hi Kevin, 
  
 ok. As far as I understand, we use the SessionStateBehavior.ReadOnly setting on that other controller to trick the MVC to allow multiple concurrent Ajax calls in parallel. In fact, this setting does not really turn the controller logic to be read-only. Instead, the controller takes care for coordinating the concurrent requests to the session variables to make it thread-safe. 
  
 I’m not sure if this will be an issue in the future, depends on some architecture choices yet to make. I accidently copied this attribute to this map controller and after removing it, it just works fine. 
  
 Karsten

Hi Karsten,



If the SessionStateBehavior is ReadOnly, the seassion state cannot be updated, but we will update map information to session. Here is the description from MSDN msdn.microsoft.com/en-us/library/system.web.sessionstate.sessionstatebehavior(v=vs.110).aspx. Anything I misunderstand, please feel free to let us know.



I don’t have many insights on thread-safe of session variables. After goolge this topic, hope this would be helpful. 

sitepoint.com/forums/showthread.php?296719-Session-amp-Application-Thread-Safety.



Any other question please feel free to let us know.



Thanks,

Kevin

Hi Kevin, 
  
 on that MSDN page they write about the ReadOnly setting: “This means that session state cannot be updated.”. I think this is not really true, because you can update the session state but the System will not take precautions to allow only a single thread to operate on the session, so you’ll Need to take care for syncing youorself. At least, this is what I think. 
  
 Well, I’m not yet sure if we will have this scenario. I will contact you again if there’s a need. 
  
 Thanks! 
 Karsten

Hi Karsten, 
  
 Thanks for your information, any questions or problems you have in your project, please let us know. 
  
 Thanks, 
 Johnny