views:

262

answers:

3
+1  Q: 

asp.net MVC

Hi,

im wondering if is possible to return a serialized AMF object in a control action in ASP.net MVC anyone as tried this before?

thanks in advance.

+1  A: 

I have little to no experience with MVC but I have done some testing with writing AMF data to a Flash client. What I did was to build a Generic Handler which used ByteArray class in FluorineFX. I created an object instance and wrote it to the ByteArray with WriteObject(). I then wrote the data of the ByteArray to the Response Stream. In Flash I then used a standard URLLoader and used ReadObject() from the (URLLoader.data as ByteArray) and I had my object deserialized and ready to go. (Of course I had to do all the RemoteClass and registerClassAlias muck first)

My guess is that the MVC Action lets you access the Response Stream as well so you should be set.

Johan Öbrink
+1  A: 

I have no idea what an AMF object is (yes, i can google it but i won't). BUT, u can serialize any object in ASP.MVC. For example, returning an JSON object is an example of using the built in serialization.

check this previous SO question out:

public ActionResult MyAction()
{    
    ... 
    // Populate myObject    
    return new JsonResult{ Data = myObject };
}

So the trick here, is that you need to make sure all the objects inside one of these AMF object can be serialised. If not, then don't forget you can return a serialised anonymous object.

eg.

public ActionResult MyAction()
{    
    ... 
    // Populate myObject    
    return new JsonResult
        { 
            Data = new
            {
                Id = object.Id,
                Name = object.FirstName + ' ' object.Surname,
                .... etc ....
            }
        };
}

hth.

Pure.Krome
+1  A: 

You can also create your own ActionResult classes, if the existing ones don't allow you to emit the format that you need.

This site has information on creating custom ActionResults: http://blogs.msdn.com/jowardel/archive/2009/03/11/asp-net-rss-actionresult.aspx

AaronSieb