0

I am trying to create an api for a movie guide mobile application, now i need to return json to the user containing information about the movie.

my request url is

/mobile/details/{id}

following is the controller:

public ActionResult Details(int id)
{
 return View(kr.GetMovie(id));
}

GetMovie(id) returns an object of type Movie to the view which contains all the info;

asked Apr 11, 2012 at 10:44

3 Answers 3

2

you should use jsonresult as action to send data back

public JsonResult details(string movieName)
 {
 var data = new {
 name="Movie name"
 };
 return Json(data, JsonRequestBehavior.AllowGet);
 }
answered Apr 11, 2012 at 10:48

1 Comment

no you do not view.. this will return just an object with data.
0
public JsonResult Details(int id)
{
 return Json(kr.GetMovie(id),JsonRequestBehavior.AllowGet));
}

As long as the Movie object is serializable this will work else you need to create a viewModel that will be a representation of your Movie object

answered Apr 11, 2012 at 10:48

Comments

0
public JsonResult Details(int id)
{
 var data = kr.GetMovie(id);
 return Json(data, JsonRequestBehavior.AllowGet);
} 

You might want to look at web api also.

http://www.cleancode.co.nz/blog/739/ajax-aspnet-mvc-3

answered Apr 11, 2012 at 10:49

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.