PDA

View Full Version : Using Sencha Touch with ASP .Net MVC



atulbahl
9 Jul 2010, 12:59 PM
Any examples or leads on how to implement Sencha Touch API with ASP .Net MVC?

Thanks

Atul

tobinharris
9 Jul 2010, 3:04 PM
No examples, but I'd consider this...

Use MVC to create a RESTful API, that returns JSON payloads. Stuff like

/people/index.json
/people/101.json

I find it helps to write some unit tests against those services, it will make your life easier for ruling out if problem is in Ext or MVC.

You can then use Senchas data stores, or it's plain Ajax requests to GET data to your MVC API. POSTS should be easy to do too.

The approach will be similar with ExtJS, you could check the samples there.

Hope this helps

Tobin

atulbahl
9 Jul 2010, 8:23 PM
No examples, but I'd consider this...

Use MVC to create a RESTful API, that returns JSON payloads. Stuff like

/people/index.json
/people/101.json

I find it helps to write some unit tests against those services, it will make your life easier for ruling out if problem is in Ext or MVC.

You can then use Senchas data stores, or it's plain Ajax requests to GET data to your MVC API. POSTS should be easy to do too.

The approach will be similar with ExtJS, you could check the samples there.

Hope this helps

Tobin

Can you elaborate little bit more?

Stoot98
11 Jul 2010, 6:35 AM
Using Sencha Touch with ASP.NET MVC will no (or very little) different to using it with ExtJS. All your doing is calling your MVC Actions from the Sencha Stores and /or Ajax calls just as you would with a static json file or a PHP file.

In your MVC Action you should make sure your returning JSON data which can be interpreted by the Store. Something like this will return some data in the correct format from your ASP.NET..




public ActionResult GetData()
{
Dictionary<string, string> myData = new Dictionary<string, string>();
myData.add("Test", "Value");

string jsonString = JsonConvert.SerializeObject(myData);

new ContentResult { Content = jsonString, ContentType = "application/json" };
}


That is untested but gives you the idea (it uses the JSON.NET library which i recommend you use as it makes converting objects to JSON very easy)

Hope this gets you further down the path!

evant
11 Jul 2010, 3:03 PM
Agreed. There's no special formula for using Touch/ExtJS with MVC. It follows the same pattern and there's plenty of posts on the forum about Ext with MVC.

atulbahl
13 Jul 2010, 6:24 AM
Thanks for your prompt replies and specially explaining in detail.

Looks like we will be integrating with Sencha.

Need to understand more about licensing.

fgeorge
7 Dec 2010, 9:45 AM
How do you get to tack on the '.json' at the end of each MVC Action? Must you have the .json suffix at the end of the URL?

Stoot98
7 Dec 2010, 11:04 AM
You don't need to have the .json on the end - the .json is just the file extension of a JSON file. As long as your content type is being returned as "application/json" then you should be fine.

daorte
24 Mar 2011, 12:33 PM
Since ASP.Net MVC 1 you have a type of Action named "JsonResult", instead of return an ActionResult on your method you should return a JsonResult. and with ASP.Net MVC you have a .ToJson() method in your objects wich make all the transformation you need.

your method should look like this:


public JsonResult GetData()
{
Dictionary<string, string> myData = new Dictionary<string, string>();
myData.add("Test", "Value");

return myData.ToJson();
}


hope this help