Search Results

Search found 128 results on 6 pages for 'jsonresult'.

Page 1/6 | 1 2 3 4 5 6  | Next Page >

  • ASP.NET MVC Consume JSONResult in Bing Maps API

    - by rockinthesixstring
    I know there are a few topics on this, but I seem to be fumbling my way through with no results. I'm trying to use a controller to return JSON results to my Bin Maps functions. Here's what I have for my controller (yes it is properly returning JSON data. Function Regions() As JsonResult Dim rj As New List(Of RtnJson)() rj.Add(New RtnJson("135 Bow Meadows Drive, Cochrane, Alberta", "desc", "title")) rj.Add(New RtnJson("12 Bowridge Dr NW, Calgary, Alberta, Canada", "desc2", "title2")) Return Json(rj, JsonRequestBehavior.AllowGet) End Function Then in my script I have this, but it's not working. <script type="text/javascript"> var map = null; var centerLat = 51.045 ; var centerLon = -114.05722; var json_object = $.getJSON("<%: Url.Action("Regions", "Events")%>"); function LoadMap() { map = new VEMap('bingMap'); map.LoadMap(new VELatLong(centerLat, centerLon), 10); $.each(json_object, function () { alert(this.address); //this alert is returning "address is undefined" StartGeocoding(this.address, this.title, this.desc); }); } function StartGeocoding(address, title, desc) { map.Find(null, // what address, // where null, // VEFindType (always VEFindType.Businesses) null, // VEShapeLayer (base by default) null, // start index for results (0 by default) null, // max number of results (default is 10) null, // show results? (default is true) null, // create pushpin for what results? (ignored since what is null) true, // use default disambiguation? (default is true) false, // set best map view? (default is true) GeocodeCallback); // call back function } function GeocodeCallback(shapeLayer, findResults, places, moreResults, errorMsg) { var bestPlace = places[0]; // Add pushpin to the *best* place var location = bestPlace.LatLong; var newShape = new VEShape(VEShapeType.Pushpin, location); var desc = "Latitude: " + location.Latitude + "<br>Longitude:" + location.Longitude; newShape.SetDescription(desc); newShape.SetTitle(bestPlace.Name); map.AddShape(newShape); } $(document).ready(function () { LoadMap(); }); </script>

    Read the article

  • How to redirect to a controller action from a JsonResult method in asp.net mvc?

    - by Pandiya Chendur
    I am fetching records for a user based on his UserId as a JsonResult... public JsonResult GetClients(int currentPage, int pageSize) { if (Session["UserId"] != "") { var clients = clirep.FindAllClients().AsQueryable(); var count = clients.Count(); var results = new PagedList<ClientBO>(clients, currentPage - 1, pageSize); var genericResult = new { Count = count, Results = results }; return Json(genericResult); } else { //return RedirectToAction("Index","Home"); } } How to redirect to a controller action from a JsonResult method in asp.net mvc?Any suggestion...

    Read the article

  • Use RedirectToAction in a JsonResult Action?

    - by CmdrTallen
    Hi, using ASP.NET MVC 1.0 and I have a action that returns a JsonResult and I need to redirect another action that also returns a JsonResult action type. The problem is the RedirectToAction() returns a RedirectToRouteResult class and seems there is no way to convert that to JsonResult class ? This is the error I am getting; Error 124 Cannot implicitly convert type 'System.Web.Mvc.RedirectToRouteResult' to 'System.Web.Mvc.JsonResult'

    Read the article

  • JSONResult to String

    - by Dustin Laine
    I have a JsonResult that is working fine, and returning JSON from some POCO's. I want to save the JSON as a string in a DB. public JsonResult GetJSON() { JsonResult json = new JsonResult { Data = GetSomPocos() }; return json; } I need to audit the response, so I want to save the json into a DB. I am having trouble finding a way to get the JSON as a string. Any help is appreciated.

    Read the article

  • Returning JsonResult From ASP.NET MVC 2.0 Controller and Unit Testing

    This post will show how to return a simple Json result from an ASP.NET MVC 2.0 web project.  It will show how to test that result inside a unit test and essentially pick apart the Json, just like a JavaScript (or other client) would do.  It seems like it should be very simple (and indeed, [...]...Did you know that DotNetSlackers also publishes .net articles written by top known .net Authors? We already have over 80 articles in several categories including Silverlight. Take a look: here.

    Read the article

  • Returning JsonResult From ASP.NET MVC 2.0 Controller and Unit Testing

    This post will show how to return a simple Json result from an ASP.NET MVC 2.0 web project.  It will show how to test that result inside a unit test and essentially pick apart the Json, just... This site is a resource for asp.net web programming. It has examples by Peter Kellner of techniques for high performance programming...Did you know that DotNetSlackers also publishes .net articles written by top known .net Authors? We already have over 80 articles in several categories including Silverlight. Take a look: here.

    Read the article

  • json returned from a jsonresult in asp.net mvc .....

    - by Pandiya Chendur
    I am returning this from a json result from a controller, var genericResult = new { redirectUrl = Url.Action("Create", "Registration") , isRedirect = true }; return Json(genericResult); but when i inspect through firebug, {"redirectUrl":"/","isRedirect":true} if (data.isRedirect) { window.location.href = json.redirectUrl; } Any suggestion.... How to redirect?

    Read the article

  • MVC JsonResult with the [Authorize] attribute going to Logon but not displaying the view

    - by likestoski
    I am seeing odd behavior with MVC 3 methods that return a JsonResult when used with the Authorize attribute. What looks like happens is the Authorize is correctly evaluated when I am not logged in but instead of redirecting to the logon form the Json response is the logon form. Is there an addition attribute that directs the response to not return a value but instead redirect the user to the logon form, preferebly with the correct returnUrl value? What I did as a demo was to setup a new MVC3 site and added AspNetMembership to my DB using the aspnet_regsql.exe command. All that is setup and logging me in correctly. The behavior of the JsonResult doesn't seem right and I'm hoping I have just missed an attribute to make it work properly. Any help is greatly appreciated, thanks in advance. Here is the Account Controller (leaving out the Post action which is not part of this question). public class AccountController : Controller { public ActionResult LogOn() { return View(); } [Authorize] public JsonResult AuthorizedAction() { return Json("Only returns if I am authorized"); } } Here is the Html markup: <script src="@Url.Content("~/Scripts/jquery-ui-1.8.11.min.js")" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function () { $("#btnTest").click(function () { $.ajax({ type: "POST", url: "Account/AuthorizedAction", data: {}, success: function (result) { $("#testMe").html(result); }, error: function (result) { $("#testMe").html('Something broke in the ajax request'); } }); }); }); </script> <input type="button" id="btnTest" value="Test me" /> <div id="testMe">I have initial text</div> The Result: 1) When logged in I get 'Only returns if I am authorized' in my test div 2) When not logged and I have a break point in my Logon() method I see this value Request["returnUrl"] "/Account/AuthorizedAction" The test div I have displays the logon form :) this seems like I'm just not handling this properly.

    Read the article

  • JsonResult shows up a file download in browser

    - by joshb
    I'm trying to use jquery.Ajax to post data to an ASP.NET MVC2 action method that returns a JsonResult. Everything works great except when the response gets back to the browser it is treated as a file download instead of being passed into the success handler. Here's my code: Javascript: <script type="text/javascript"> $(document).ready(function () { $("form[action$='CreateEnvelope']").submit(function () { $.ajax({ url: $(this).attr("action"), type: "POST", data: $(this).serialize(), dataType: "json", success: function (envelopeData) { alert("test"); } }); }); return false; }); </script> Action method on controller: public JsonResult CreateEnvelope(string envelopeTitle, string envelopeDescription) { //create an envelope object and return return Json(envelope); } If I open the downloaded file the json is exactly what I'm looking for and the mime type is shown as application/json. What am I missing to make the jquery.ajax call receive the json returned?

    Read the article

  • Problem in JsonResult

    - by Saravanan I M
    I am using the jsonresult for listing all the cities under a country. I retrieve the data from database and load it to a dropdown list using jquery. The problem is if the cities goes beyond 3000 then the jsonresult is not working. <script type="text/javascript"> $(document).ready(function () { //Hook onto the MakeID list's onchange event $("#Country").change(function () { //build the request url $("#HomeTown").empty(); var url = '<%= Url.Content("~/") %>' + "Location/GetCitiesByCountry/" + $("#Country").val(); $.getJSON(url, function (data) { $.each(data, function (index, optionData) { $("#HomeTown").append("<option value='" + optionData.geonameid + "'>" + optionData.asciiname + "</option>"); }); $("#HomeTown").option[0].selected = true; }); }).change(); }); </script>

    Read the article

  • Beginner problem with posting data table to JsonResult

    - by ognjenb
    With this script I get data from JsonResult (GetDevicesTable) and put them to table ( id="OrderDevices") <script type="text/javascript"> $(document).ready(function() { $("#getDevices a").click(function() { var Id = $(this).attr("rel"); var rowToMove = $(this).closest("tr"); $.post("/ImportXML/GetDevicesTable", { Id: Id }, function(data) { if (data.success) { //remove row rowToMove.fadeOut(function() { $(this).remove() }); //add row to other table $("#OrderDevices").append("<tr><td>"+ data.DeviceId+ "</td><td>" + data.Id+ "</td><td>" + data.OrderId + "</td></tr>"); } else { alert(data.ErrorMsg); } }, "json"); }); }); <% using (Html.BeginForm()) {%> <table id="OrderDevices" class="data-table"> <tr> <th> DeviceId </th> <th> Id </th> <th> OrderId </th> </tr> </table> <p> <input type="submit" value="Submit" /> </p> <% } %> When click on Submit I need something like this: $(document).ready(function() { $("#submit").click(function() { var Id = $(this).attr("rel"); var DeviceId = $(this).attr(???); var OrderId = $(this).attr(???); var rowToMove = $(this).closest("tr"); $.post("/ImportXML/DevicesActions", { Id: Id, DeviceId:DeviceId, OrderId:OrderId }, function(data) { }, "json"); }); }); I have problem with this script because do not know how post data to this JsonResult: public JsonResult DevicesActions(int Id,int DeviceId,int OrderId) { orderdevice ord = new orderdevice(); ord.Id = Id; ord.OrderId = DeviceId; ord.DeviceId = OrderId; DBEntities.AddToorderdevice(ord); DBEntities.SaveChanges(); }

    Read the article

  • MVC JsonResult not working with chrome?

    - by Karsten Detmold
    i want jquery to take a JsonResult from my MVC controller but it does'nt receive any data! If I put the output into a textfile and enter its link its working so I think my jQuery is fine. Then I was testing with other browsers like chrome and I saw NOTHING. The requested page was just emtpy.. no errors. Also IE seems to have problems receiving my string.. only firefox displays the string but why? public JsonResult jsonLastRequests() { List<Request> requests = new List<Request>(); while (r.Read()) { requests.Add(new Models.Request() { ID = (int)r[0], SiteID = r[1].ToString(), Lat = r[2].ToString(), City = r[4].ToString(), CreationTime = (DateTime)r[5] }); } r.Close(); return Json(requests); } I found out that also if I want to return the JSON as string its not working! Its working with a string in all browsers now.. but jQuery is still not loading anything var url = "http://../jsonLastRequests"; var source = { datatype: "json", datafields: [ { name: 'ID' }, { name: 'SiteID' }, { name: 'Lat' }, { name: 'CreationTime' }, { name: 'City' }, ], id: 'id', url: url }; var dataAdapter = new $.jqx.dataAdapter(source, { downloadComplete: function (data, status, xhr) { }, loadComplete: function (data) { }, loadError: function (xhr, status, error) { } }); I fixed my problem by adding: access-control-allow-origin:*

    Read the article

  • Asp.net MVC jQuery Ajax calls to JsonResult return no data

    - by Maslow
    I have this script loaded on a page: (function() { window.alert('bookmarklet started'); function AjaxSuccess(data, textStatus, xmlHttpRequest) { if (typeof (data) == 'undefined') { return alert('Data is undefined'); } alert('ajax success' + (data || ': no data')); } function AjaxError(xmlHttpRequest, textStatus, errorThrown) { alert('ajax failure:' + textStatus); } /*imaginarydevelopment.com/Sfc*/ var destination = { url: 'http://localhost:3041/Bookmarklet/SaveHtml', type: 'POST', success: AjaxSuccess, error: AjaxError, dataType: 'text',contentType: 'application/x-www-form-urlencoded' }; if (typeof (jQuery) == 'undefined') { return alert('jQuery not defined'); } if (typeof ($jq) == 'undefined') { if (typeof ($) != 'undefined') { $jq = $; } else { return alert('$jq->jquerify not defined'); } } if ($jq('body').length <= 0) { return alert('Could not query body length'); } if ($jq('head title:contains(BookmarkletTest)').length > 0) { alert('doing test'); destination.data = { data: 'BookmarkletTestAjax' }; $jq.ajax(destination); return; } })(); when it is run locally in VS2008's cassini the ajax success shows the returned string from Asp.net MVC, when it is run remotely the ajax success data is null. Here's the controller method that is firing both locally and when run remotely: [AcceptVerbs(HttpVerbs.Post | HttpVerbs.Get)] public string SaveHtml(string data) { var path = getPath(Server.MapPath); System.IO.File.WriteAllText(path,data); Console.WriteLine("SaveHtml called"); Debug.WriteLine("SaveHtml called"); //return Json(new { result = "SaveHtml Success" }); return "SaveHtml Success"; } Once i have it working I was going to remove the GET, but currently accessing the SaveHtml method directly from the webbrowser produces the expected results when testing. So there's something wrong in my javascript I believe, because when I step through there with chrome's developer tools, I see the data is null, and the xmlHttpRequest doesn't appear to have the expected result in it anywhere either. I'm loading jquery via http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js

    Read the article

  • Problme in JsonResult

    - by Saravanan I M
    I am using the jasonresult for listing all the cities under a country. I retrieve the data from database and load it to a dropdown list using jquery. The problem is if the cities goes beyond 3000 then the jasonresult is not working. $(document).ready(function () { //Hook onto the MakeID list's onchange event $("#Country").change(function () { //build the request url $("#HomeTown").empty(); var url = '' + "Location/GetCitiesByCountry/" + $("#Country").val(); $.getJSON(url, function (data) { $.each(data, function (index, optionData) { $("#HomeTown").append("" + optionData.asciiname + ""); }); $("#HomeTown").option[0].selected = true; }); }).change(); });

    Read the article

  • Problem with JSONResult

    - by vikitor
    Hi, I' still newby to this so I'll try to explain what I'm doing. Basically what I want is to load a dropdownlist depending on the value of a previous one, and I want it to load the data and appear when the other one is changed. This is the code I've written in my controller: public ActionResult GetClassesSearch(bool ajax, string phylumID, string kingdom){ IList<TaxClass> lists = null; int _phylumID = int.Parse(phylumID); int _kingdom = int.Parse(kingdom); lists = _taxon.getClassByPhylumSearch(_phylumID, _kingdom); return Json(lists.count); } and this is how I call the method from the javascript function: function loadClasses(_phylum) { var phylum = _phylum.value; $.getJSON("/Suspension/GetClassesSearch/", { ajax: true, phylumID: phylum, kingdom: kingdom }, function(data) { alert(data); alert('no fallo') document.getElementById("pClass").style.display = "block"; document.getElementById("sClass").options[0] = new Option("-select-", "0", true, true); //for (i = 0; i < data.length; i++) { // $('#sClass').addOption(data[i].classID, data[i].className); //} }); } The thing is that just like this it works, I pass the function the number of classes within a selected phylum, and it displays the pclass element, the problem gets when I try to populate the slist with data (which should contain the objects retrieved from the database), because when there is data returned by the database changing return Json(lists) instead of return Json(lists.count) I keep getting the same error: A circular reference was detected while serializing an object of type 'SubSonic.Schema.DatabaseColumn'. I've been going round and round debugging and making tests but I can't make it work, and it is suppossed to be a simple thing, but I'm missing something. I have commented the for loop because I'm not quite sure if that's the way you access the data, because I've not been able to make it work when it finds records. Can anyone help me? Thanks in advance, Victor

    Read the article

  • How to either return JSON or RedirectToAction?

    - by DaveDev
    I have an Action Method that I'd either like to return JSON from on one condition or redirect on another condition. I thought that I could do this by returning ActionResult from my method but doing this causes the error "not all code paths return a value" Can anyone tell me what I'm doing wrong? Or how to achieve the desired result? Here's the code below: [AcceptVerbs(HttpVerbs.Post)] public ActionResult Login(User user) { var myErrors = new Dictionary<string, string>(); try { if (ModelState.IsValid) { if (userRepository.ValidUser(user)) { RedirectToAction("Index", "Group"); //return Json("Valid"); } else { return Json("Invalid"); } } else { foreach (KeyValuePair<string, ModelState> keyValuePair in ViewData.ModelState) { if (keyValuePair.Value.Errors.Count > 0) { List<string> errors = new List<string>(); myErrors.Add(keyValuePair.Key, keyValuePair.Value.Errors[0].ErrorMessage); } } return Json(myErrors); } } catch (Exception) { return Json("Invalid"); } }

    Read the article

  • Django and json request

    - by Hulk
    In a template i have the following code <script> var url="/mypjt/my_timer" $.post(url, paramarr, function callbackHandler(dict) { alert('got response back'); if (dict.flag == 2) { alert('1'); $.jGrowl("Data could not be saved"); } else if(dict.ret_status == 1) { alert('2'); $.jGrowl("Data saved successfully"); window.location = "/mypjt/display/" + dict.rid; } }, "json" ); </script> In views i have the following code, def my_timer(request): dict={} try: a= timer.objects.get(pk=1) dict({'flag':1}) return HttpResponse(simplejson.dumps(dict), mimetype='application/javascript') except: dict({'flag':1}) return HttpResponse(simplejson.dumps(dict), mimetype='application/javascript') My question is since we are making a json request and in the try block ,after setting the flag ,cant we return a page directly as return render_to_response('mypjt/display.html',context_instance=RequestContext(request,{'dict': dict})) instead of sending the response, because on success again in the html page we redirect the code Also if there is a exception then only can we return the json request. My only concern is that the interaction between client and server should be minimal. Thanks..

    Read the article

  • Is it possible to return as SiteMap as a JsonResult?

    - by Paul Suart
    I've got a very simple Action on my Controller that's attempting to return my XmlSiteMap as a JsonResult: public ActionResult Index() { var nodes = SiteMap.Provider.RootNode; return new JsonResult() { Data = nodes, JsonRequestBehavior = JsonRequestBehavior.AllowGet }; } However, when I call the Action, an InvalidOperationException is thrown: "A circular reference was detected while serializing an object of type 'System.Web.SiteMapNode'." Is there a way to Json serialize a SiteMap, or indeed any object that has children of the same type?

    Read the article

  • Is it possible to return a SiteMap as a JsonResult?

    - by Paul Suart
    I've got a very simple Action on my Controller that's attempting to return my XmlSiteMap as a JsonResult: public ActionResult Index() { var nodes = SiteMap.Provider.RootNode; return new JsonResult() { Data = nodes, JsonRequestBehavior = JsonRequestBehavior.AllowGet }; } However, when I call the Action, an InvalidOperationException is thrown: "A circular reference was detected while serializing an object of type 'System.Web.SiteMapNode'." Is there a way to Json serialize a SiteMap, or indeed any object that has children of the same type?

    Read the article

  • Passing JSON object from Controller to View(jsp)

    - by user752233
    I am trying to send JSON object to my view from controller but unable to send it. Please help me out! I am using following code public class SystemController extends AbstractController{ protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { ModelAndView mav = new ModelAndView("SystemInfo", "System", "S"); response.setContentType("application/json;charset=UTF-8"); response.setHeader("Cache-Control", "no-cache"); JSONObject jsonResult = new JSONObject(); jsonResult.put("JVMVendor", System.getProperty("java.vendor")); jsonResult.put("JVMVersion", System.getProperty("java.version")); jsonResult.put("JVMVendorURL", System.getProperty("java.vendor.url")); jsonResult.put("OSName", System.getProperty("os.name")); jsonResult.put("OSVersion", System.getProperty("os.version")); jsonResult.put("OSArchitectire", System.getProperty("os.arch")); response.getWriter().write(jsonResult.toString()); // response.getWriter().close(); return mav; // return modelandview object } } and in the view side I am using <script type="text/javascript"> Ext.onReady(function(response) { //Ext.MessageBox.alert('Hello', 'The DOM is ready!'); var showExistingScreen = function () { Ext.Ajax.request({ url : 'system.htm', method : 'POST', scope : this, success: function ( response ) { alert('1'); var existingValues = Ext.util.JSON.decode(response.responseText); alert('2'); } }); }; return showExistingScreen(); });

    Read the article

  • mvc2 migration issue

    - by Sefer KILIÇ
    i migrate my mvc1 project to mvc2. my jquery json result function does not work anymore. have any idea ? aspx $.getJSON('Customer/GetWarningList/0', function(jsonResult) { $.each(jsonResult, function(i, val) { $('#LastUpdates').prepend(jsonResult[i].Url); }); }); controller public JsonResult GetWarningList(string id) { List<WarningList> OldBck = new List<WarningList>(); return this.Json(OldBck); }

    Read the article

1 2 3 4 5 6  | Next Page >