jsonresult

MVC 4 and JsonResult format

て烟熏妆下的殇ゞ 提交于 2019-12-07 17:07:33
问题 have a problem with the result format of this code public JsonResult getCategorias(int? id) { var res = from c in db.Categorias where (( id.HasValue && c.CategoriaPadre == id.Value) || (!id.HasValue && c.CategoriaPadre == null)) select new { id = c.Id, label = c.Descripcion }; return this.Json(res, JsonRequestBehavior.AllowGet); } this return a json : [{"id":21,"label":"Marketing3"},{"id":22,"label":"Marketing4"}] But i need a json with this format: {"21":"Marketing3","22":"Marketing4"} What

How to read a property of an anonymous type?

泪湿孤枕 提交于 2019-12-06 20:16:07
问题 I have a method that returns return new System.Web.Mvc.JsonResult() { Data = new { Status = "OK", } } I need to write a unit test where I need to verify that jsonResult.Data.status= "OK" . How do I read the status property? Update: I tried the [assembly: InternalsVisibleTo("TestingAssemblyName")], but that didn't help. I kept getting the error {"'System.Web.Mvc.JsonResult' does not contain a definition for 'Status'"} Besides I think I will prefer not modifying the code that I am testing. So I

how to get JSON Results placed on Google Maps?

蹲街弑〆低调 提交于 2019-12-06 07:00:54
I have my JSON Results shown below that i have pulled out of my database, Iwant to display this on google maps using a marker which is displayed based on the position here are the results; { "user": [{ "name" : "xxxxxxxxx", "posn" : [53.491314, -2.249451] }, { "name" : "xxxxxxxxxx", "posn" : [54.949231, -1.620483] }] } How do i get the user name and position placed on google maps? Coding for my googlemaps below; <div id="map_canvas" style="width:800px; height:600px;"></div> <script type="text/javascript"src="http://maps.googleapis.com/maps/api/js?sensor=false"></script> <script src="/Scripts

MVC 4 and JsonResult format

牧云@^-^@ 提交于 2019-12-05 23:29:57
have a problem with the result format of this code public JsonResult getCategorias(int? id) { var res = from c in db.Categorias where (( id.HasValue && c.CategoriaPadre == id.Value) || (!id.HasValue && c.CategoriaPadre == null)) select new { id = c.Id, label = c.Descripcion }; return this.Json(res, JsonRequestBehavior.AllowGet); } this return a json : [{"id":21,"label":"Marketing3"},{"id":22,"label":"Marketing4"}] But i need a json with this format: {"21":"Marketing3","22":"Marketing4"} What can i do? Thanks a lot and sorry my english. Piotr Stapp Replace your return with: var dictionary = res

Cannot implicitly convert Web.Http.Results.JsonResult to Web.Mvc.JsonResult

倖福魔咒の 提交于 2019-12-05 06:49:08
I've set up this test method on a controller to strip out any complication to it. Based off of all the results I've found from searching this should work. I'm not sure what I'm missing here. public JsonResult test() { return Json(new { id = 1 }); } This is the error I get. Cannot implicitly convert type 'System.Web.Http.Results.JsonResult' to 'System.Web.Mvc.JsonResult' you should return a JsonResult instead of just Json public JsonResult test() { var result = new JsonResult(); result.Data = new { id = 1 }; result.JsonRequestBehavior = JsonRequestBehavior.AllowGet; return result; } Try the

The length of the string exceeds the value set on the maxJsonLength property. in MVC3

喜你入骨 提交于 2019-12-04 06:32:04
问题 MVC3 (.cshtml File) $.getJSON(URL, Data, function (data) { document.getElementById('divDisplayMap').innerHTML = data; if (data != null) { $('#myTablesId').show(); tdOnclickEvent(); } else { $('#myTablesId').hide(); } }).error(function (xhr, ajaxOptions, thrownError) { debugger; }); on Server Side public JsonResult ZoneType_SelectedState(int x_Id, int y_Id) { JsonResult result = new JsonResult(); result.Data = "LongString";//Longstring with the length mention below return Json(result.Data,

Return Multiple Objects Using ASP.NET MVC'S JsonResult Class

让人想犯罪 __ 提交于 2019-12-03 15:45:35
Is it possible to Multiple Objects Using ASP.NET MVC'S JsonResult Class.... Here is a controller method which returns json object of my records but i also want to pass the count value.... var materials = consRepository.FindAllMaterials().AsQueryable(); var count = materials.Count(); var results = new PagedList<MaterialsObj>(materials, currentPage-1, pageSize); return Json(results); How to return count along with the results from asp.net mvc controller.... How about creating an anonymous type and JSON'ing that? e.g. var resultCount = results.Count; var genericResult = new { Count = resultCount,

Can I convert a JSON string into JsonResult?

左心房为你撑大大i 提交于 2019-12-03 00:53:30
问题 I have some stored JSON strings stored in the DB which I want to return to the client as JsonResult . I know that Json(object) turns an object into JsonResult but what if I already have the result in a string ? can I cast it to JsonResult 回答1: You don't need to return a JsonResult because its job is to serialize an object into JSON string. You already have the JSON string, so just return it in a ContentResult and specify the correct content type: string json = //get some json from your DB

Can I convert a JSON string into JsonResult?

非 Y 不嫁゛ 提交于 2019-12-02 14:16:50
I have some stored JSON strings stored in the DB which I want to return to the client as JsonResult . I know that Json(object) turns an object into JsonResult but what if I already have the result in a string ? can I cast it to JsonResult Erv Walter You don't need to return a JsonResult because its job is to serialize an object into JSON string. You already have the JSON string, so just return it in a ContentResult and specify the correct content type: string json = //get some json from your DB return new ContentResult { Content = json, ContentType = "application/json" }; Remember that your

The length of the string exceeds the value set on the maxJsonLength property. in MVC3

非 Y 不嫁゛ 提交于 2019-12-02 13:08:18
MVC3 (.cshtml File) $.getJSON(URL, Data, function (data) { document.getElementById('divDisplayMap').innerHTML = data; if (data != null) { $('#myTablesId').show(); tdOnclickEvent(); } else { $('#myTablesId').hide(); } }).error(function (xhr, ajaxOptions, thrownError) { debugger; }); on Server Side public JsonResult ZoneType_SelectedState(int x_Id, int y_Id) { JsonResult result = new JsonResult(); result.Data = "LongString";//Longstring with the length mention below return Json(result.Data,"application/json", JsonRequestBehavior.AllowGet); } from the server side i am passing the string with the