views:

48

answers:

1

I returned json result from a controller but how can i add a view that uses this json result..

 public class MaterialsController : Controller
 {
    ConstructionRepository consRepository = new ConstructionRepository();
    public JsonResult Index()
    {
        var materials = consRepository.FindAllMaterials().AsQueryable();
        return Json(materials);
    }
 }

How to add a view to this? Any suggestion...

A: 

If are returning JsonResult view will not be attached to it. It will be pure Json that will be sent to the browser.

However you can use Asp.Net ClientSide template or JQuery Client Templates to render view using this Json. An example

http://jtemplates.tpython.com/

http://weblogs.asp.net/dwahlin/archive/2009/05/03/using-jquery-with-client-side-data-binding-templates.aspx

Amitabh