Json e ASP.NET MVC

mercoledì 19 maggio 2010 - 12.03

volperubbia Profilo | Senior Member

Ciao a tutti,
in una View di un'applicazione ASP.NET MVC vorrei popolare una Ext.grid.GridPanel
a partire da un JsonResult definito nel controller ...

Public Class SettingsController : Inherits System.Web.Mvc.Controller
Function Users() As ActionResult
' obj è un System.Collections.Generic.IList(Of T)
Return Json(New With {.data = obj, .totalCount = obj.Count}, JsonRequestBehavior.AllowGet)
End Function
End Class

Nella view ho:

<div id="usersDiv"></div>

<script type="text/javascript">
Ext.onReady(function() {
var div = Ext.get('usersDiv');
var store = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({ url: 'Settings/Users' }),
reader: new Ext.data.JsonReader(
{ root: 'Settings' },
[{ name: 'USERCODE'}]
)
});

var grid = new Ext.grid.GridPanel({
store: store,
idProperty: 'USERCODE',
remoteSort: true,
autoLoad: true,
columns: [
{ header: 'USERCODE', width: 120, sortable: true, dataIndex: 'USERCODE' }
],
renderTo: div,
title: 'My First Grid',
width: 600,
height: 250,
frame: true
});
});
</script>

In pratica, quando accedo alla view, anzichè popolarmi la grid, mi fa il download
di un file di testo con dentro l'elenco degli utenti.

Penso sia errata la Function Users, qualche idea su come procedere?

Grazie per l'attenzione,
Davide
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5