2011-10-04 17 views
5

Ho un problema con un risultato JSON. Quando si chiama da jquery, viene restituito un file da salvare anziché eseguire la funzione di successo. La richiesta get jquery si verifica nella funzione document.ready.Controller MVC3 che restituisce JsonFile

Qualsiasi aiuto sarebbe apprezzato.

public ActionResult Locations() 
    { 
     LocationsModel lm = new LocationsModel(); 
     return Json(lm.getPins(), JsonRequestBehavior.AllowGet); 
    } 

Ho anche provato:

public JsonResult Locations() 
    { 
     LocationsModel lm = new LocationsModel(); 
     return Json(lm.getPins(), JsonRequestBehavior.AllowGet); 
    } 

jQuery è la seguente:

$.ajax({ 
     type: "POST", 
     contentType: "application/json; charset=utf-8", 
     url: this.href, 
     data: "{}", 
     dataType: "json", 
     success: function (msg) { getPins_success(msg); }, 
     error: OnError 
    }); 

Grazie, Chris

Edit:

Non importa che fosse un duh. Una volta trasferita la richiesta json a un'altra azione nel controller e caricata la vista, tutto si è risolto. Ora sto analizzando i problemi ma questo è un altro problema tutti insieme.

+2

'AllowGet' e' type: "POST" '? –

risposta

1

invece si dovrebbe usare getJson.

Per voi sarebbe:

$.getJSON(this.href, function (msg) { getPins_success(msg); }); 

Questo vi permetterà di analizzare i dati di ritorno come JSON.

Problemi correlati