1. #1
    Ext User
    Join Date
    Jul 2010
    Posts
    3
    Vote Rating
    0
    atulbahl is on a distinguished road

      0  

    Default Using Sencha Touch with ASP .Net MVC

    Using Sencha Touch with ASP .Net MVC


    Any examples or leads on how to implement Sencha Touch API with ASP .Net MVC?

    Thanks

    Atul

  2. #2
    Ext User tobinharris's Avatar
    Join Date
    Apr 2008
    Location
    Leeds, UK
    Posts
    34
    Vote Rating
    1
    tobinharris is on a distinguished road

      0  

    Default


    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
    tobinharris.com
    Leeds, UK
    Co-author of NHibernate in Action
    Likes iPhone, iPad, HTML5, .NET and Ruby on Rails

    Developer and Founder at engineroomapps.com

  3. #3
    Ext User
    Join Date
    Jul 2010
    Posts
    3
    Vote Rating
    0
    atulbahl is on a distinguished road

      0  

    Default


    Quote Originally Posted by tobinharris View Post
    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?

  4. #4
    Sencha User
    Join Date
    Feb 2009
    Location
    Glasgow, Scotland
    Posts
    281
    Vote Rating
    1
    Stoot98 will become famous soon enough

      0  

    Default


    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..

    Code:
    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!

  5. #5
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    16,645
    Vote Rating
    583
    evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute

      0  

    Default


    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.
    Evan Trimboli
    Sencha Developer
    Twitter - @evantrimboli
    Don't be afraid of the source code!

  6. #6
    Ext User
    Join Date
    Jul 2010
    Posts
    3
    Vote Rating
    0
    atulbahl is on a distinguished road

      0  

    Default Thanks

    Thanks


    Thanks for your prompt replies and specially explaining in detail.

    Looks like we will be integrating with Sencha.

    Need to understand more about licensing.

  7. #7
    Ext User
    Join Date
    Jul 2010
    Posts
    32
    Vote Rating
    0
    fgeorge is on a distinguished road

      0  

    Default


    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?

  8. #8
    Sencha User
    Join Date
    Feb 2009
    Location
    Glasgow, Scotland
    Posts
    281
    Vote Rating
    1
    Stoot98 will become famous soon enough

      0  

    Default


    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.

  9. #9
    Sencha User
    Join Date
    Apr 2009
    Location
    Venezuela
    Posts
    2
    Vote Rating
    0
    daorte is on a distinguished road

      0  

    Default


    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:

    PHP Code:
    public JsonResult GetData() 
    {
        
    Dictionary<stringstringmyData = new Dictionary<stringstring>();
        
    myData.add("Test""Value");

        return 
    myData.ToJson();


    hope this help

Similar Threads

  1. ASP.NET MVC with ExtJS
    By jenfoong in forum Ext 3.x: Help & Discussion
    Replies: 0
    Last Post: 8 Mar 2010, 11:38 PM
  2. Problem combining extjs 2.0 with asp.net/ asp.net mvc/html
    By ritcoder in forum Ext 2.x: Help & Discussion
    Replies: 1
    Last Post: 12 Jul 2008, 3:58 PM
  3. MVC for asp.net/VS 2008
    By DragonFist in forum Community Discussion
    Replies: 15
    Last Post: 16 Jun 2008, 7:47 AM
  4. Replies: 2
    Last Post: 4 Feb 2008, 2:05 PM

Thread Participants: 5

Tags for this Thread