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;

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);
        }
Sign up to request clarification or add additional context in comments.

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

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

Comments

Your Answer

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.