Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NETMVCJSON
Hi
I am new to asp.net mvc3 and Json
how to create json service in asp.net mvc3
Is it possible to connect ms sql database from json service (with in asp.net mvc3 app)
and can we use this same json service at Iphone client
If anybody knows the answer please give me a sample app for json in asp.net mvc3
Posted 24-Apr-12 1:43am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You don't need to create a JSON service in MVC. You just need to return a JsonResult from your controller action method. The ways of connecting to a sql database from a controller action method are exactly the same as other .net sql connections. You should be able to reuse some of the action methods for the Json from other applications.
 
I'm not going to give you a sample app, but you can see what the manufacturers have in the way of documentation and samples:
 
www.asp.net/mvc/mvc3[^]
  Permalink  
Comments
member60 at 17-May-12 0:44am
   
my 5!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

As jim lahey said "You don't need to create a JSON service in MVC. You just need to return a JsonResult from your controller action method"
 
The link below will show you how to :
"Building an MVC 3 App with Model First and Entity Framework 4.1"
That helps you, connect to sql server db throw Entity Framework
 
Then make a Blog Controller contains the code below
public class BlogController : Controller
{
   private BlogModelContainer db = new BlogModelContainer();
 
   public JsonResult Index()
   { 
      IList<blog> blogs = db.Blogs.ToList();
      return Json(blogs, JsonRequestBehavior.AllowGet);
   }
}
After you call Index Action From Blog Controller (/Blog/Index/) you will get something like this:
[{"Id":1,"Title":"Title 1","BloggerName":"Blogger Name 1"},{"Id":2,"Title":"Title 2","BloggerName":"Blogger Name 2"},{"Id":3,"Title":"Title 3","BloggerName":"Blogger Name 3"},{"Id":5,"Title":"Title 5","BloggerName":"Blogger Name 5"},{"Id":7,"Title":"Title 7","BloggerName":"Blogger Name 7"},{"Id":8,"Title":"Title 8","BloggerName":"Blogger Name 8"},{"Id":10,"Title":"Title 1","BloggerName":"Blogger Name 10"}]
  Permalink  
v2
Comments
Member 8700016 at 25-Apr-12 0:12am
   
can I use this service to Iphone if yes how
Nikfazan at 25-Apr-12 6:54am
   
Have a look at this: "http://www.microsoft.com/web/post/connecting-the-iphone-with-aspnet-web-pages" Hope it helps

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 397
1 OriginalGriff 350
2 thatraja 205
3 Emre Ataseven 165
4 Shai Vashdi 150
0 Sergey Alexandrovich Kryukov 8,894
1 OriginalGriff 5,200
2 Peter Leow 3,955
3 Maciej Los 3,535
4 Abhinav S 3,208


Advertise | Privacy | Mobile
Web02 | 2.8.140415.2 | Last Updated 15 May 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid