How to create ActionResult for "Details" functionality in internet application of MVC 4.0?

Model-View-Controller is a very vast topic hence I try to cover it in small articles. I have developed this code using Microsoft Visual Studio - Ultimate Edition 2012 and with the help of MVC4.0 Razor engine is used in this.

Significance and usage of ActionResult:
Always its controller's duty to convey ASP.NET MVC Framework to show the view by returning a ViewResult.
ActionResult indicates the next steps that should be taken to process the request.Every controller action is expected to provide the return value.

using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Net.Http.Formatting;
using System.Net.Http.Headers;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using yournamespacename.Models;
namespace yournamespacename.Controllers
public class yourControllername : Controller
yourclassname obj = null;
public ActionResult Details(int id)
var obj_client = new HttpClient();
var obj_task = obj_client.GetAsync("http://localhost:yourportnumber/api/your_controller_name/" + id.ToString())
.ContinueWith((task_readresult) =>
var response = task_readresult.Result;
var obj_read_asyn = response.Content.ReadAsAsync();
obj = obj_read_asyn.Result;
return View(obj);

You can either set the return type as JsonResult or simply it will be ActionResult.
Json() It returns a JsonResult which serializes an object and renders it in JSON format.


No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: