MVC :: Using Jsonresult Actions To Pass Json Data To Third Party Apps?
Oct 9, 2010
i want to use MVC 2 actions to pass JSON data to a 3rd party application via a URL.The URL will be in the form of http://www.abc.com/controller/action..I am using JSonResultHow can i test the output of this URL to ensure the JSON is properly formed..
View 2 Replies
Similar Messages:
Jan 31, 2011
How can I get the result of a method that return a JsonResult and cast into string.
[HttpPost]
public JsonResult AnalyseNbPayment(DateTime dt, DateTime dt2,int FrequencyID) {
if (FrequencyID == ApplConfig.Frequency.WEEKLY) {
return Json(new { val = GetNbWeek(dt, dt2) });
}
else if (FrequencyID == ApplConfig.Frequency.MONTHLY) {
return Json(new { val =GetDateDiffInMonth(dt, dt2) });
}
else if (FrequencyID == ApplConfig.Frequency.QUARTELY) {
return Json(new { val = GetQuarterLy(dt, dt2) });
}
else if (FrequencyID == ApplConfig.Frequency.BI_MONTLY) {
return Json(new { val = GetBiMontlhy(dt, dt2) });
}
else if(FrequencyID == ApplConfig.Frequency.YEARLY)
{
return Json(new { val = GetNbYear(dt, dt2) });
}
return Json(new { val =0 });
}
I want to call my method like this
string MyValue = AnalyseNbPayment(Convert.ToDateTime(ViewModel.oRent.DateFrom), Convert.ToDateTime(ViewModel.oRent.DateTo), Convert.ToInt32(oLease.FrequencyID)).val.ToString(); <br />
View 1 Replies
Apr 21, 2010
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
View 2 Replies
Aug 10, 2010
I am set up a series of pages like so...Page 1: User is presented a series of checkboxes. Each checkbox represents a group.<User makes selection and submits form, Controller validates input and send selected list to next action>Page 2: User is presented a series of checkboxes of items within the groups he/she selected in step 1.<User makes selection and submits form, Controller validates input and send selected list to next action>
View 2 Replies
Mar 13, 2011
I have one controller that takes a username and pass and checks against a database. IF the user is authenticated, I want to call an overloaded action on another controller.
My end goal is to authenticate a user against an old table from a MySQL db (I have this part working). Once the user is authenticated, I would like to be able to "automagically" forward the person to the built in MVC registration page but I would like to populate some fields in the view using data obtained from the first controller (the old databse info).
When I try something like what I have below I get an error about the Register() methods being ambiguous. I've also tried using the [ActionName("Register2")] attribute but then the error returned says it cant find a method named Register2.
[Code]....
View 2 Replies
Feb 23, 2010
i'm facing a problem with transfering data between two web applicatins on two different servers. For example on page A
I have a login box with LoginName textbox and Password textbox and Login button. What I am trying to achieve is that when i press Login button I will transfer data from Login and Password textboxes to page B and .net code on page B will try to validate the logging user. I was trying code like this but it won't works on page A
[Code]....
and on page B in Page_Load event
[Code]....
I was thinking of using Web Service between these apps, however i am not certain that it will works.
View 12 Replies
Sep 20, 2010
I had my ASP.NET MVC actions written like this:
//
// GET: /TaxStatements/CalculateTax/{prettyId}
public ActionResult CalculateTax(int prettyId)
{
if (prettyId == 0)
return Json(true, JsonRequestBehavior.AllowGet);
TaxStatement selected = _repository.Load(prettyId);
return Json(selected.calculateTax, JsonRequestBehavior.AllowGet); // calculateTax is of type bool
}
I had problems with this because when using it in jquery functions I had all sorts of error, mostly toLowerCase() function failing.
So I had to change the actions in a way that they return bool as string (calling ToString() on bool values), so that thay return "true" or "false" (in the qoutes) but I kinda don't like.
How others handle such a case?
View 1 Replies
Sep 6, 2010
I am having one controller Test having following actions
(1)public ActionResult ABC (string parameter1, string parameter2)
(2)public ActionResult XYZ (string parameter1, string parameter2,string parameter3, string parameter4)
i have added following html.routelinks
<%= Html.RouteLink("ABC","ABC", new { parameter1 = 100, parameter2 = 200 } )%><br />
<%= Html.RouteLink("XYZ", "XYZ", new { parameter1 = 1000 , parameter2 = 2000 }) %>
last two parameters in XYZ action are optionals so i have not passed them in Html.routelink
routes.MapRoute("ABC", "Test/{parameter1}/{parameter2}", new { controller = "Test", action = "ABC", parameter1= 0,parameter2=0 });
routes.MapRoute("XYZ", "Test/{parameter1}/{parameter2}/{parameter3}/{parameter4}", new { controller = "Test", action = "XYZ", parameter1=0,parameter2=0 ,parameter3=UrlParameter.Optional,parameter4=UrlParameter.Optional});
In above senario in both cases same route "ABC" is called eventhough i have clicked on second Html.routelink. can anyone solve this issue ? how can i route according to route name instead of number of parameters?
View 1 Replies
Feb 3, 2010
We have two different websites that run two seperate web sites (a backend and a front end) for our peice of software. The way we do our authentication is to put the user id into the session when the user logs in, all the pages on the site inherit from one base page if this base page cannot find this value in session it kicks the user out to the login screen.
What we want to be able to do is have a link on the front end after the user logs in and when they click on it it takes them(redirects them) to the back end. However I cannot think about how to do this in a secure and sensible way. I did think of putting the users username and password dynamically generated into the hyperlink that takes them from the front end to the back end. Would this be advisable. It will be clear text but then again we done use ssl in any case just plain forms authentication. I mean I will hash the values anyway but still be sending them. I suppose is there a way to share a session across two app domain without too much dificulty?
View 2 Replies
May 7, 2015
I want to send single json object with nested arrays through jquery ajax method.
In Code
In jquery ajax i am passing LeaveRuleMaster a single json object which holds some properties (Leavetypeid, Leavename, Leavestatus and nested array LeaveRulespecific.
In vb.net code i can receive the value of properties(Leavetypeid,Leavename,Leavestatus)
but i am receiving the LeaveRuleSpecific as nothing.
Based on the following link i tried this [URL] .....
View 1 Replies
Jun 29, 2010
I am getting an exception that child actions are not allowed to perform redirect actions. Although I can understand that this might is true in most situations I do believe that the framework might allow this to pass when a Child Action is calling another child action like in this example:
I have this code in my CountryController (I compacted it a bit but the main concept remains that I have a controller with Child Actions only):
[Code]....
This exception is being thrown:
Server Error in '/' Application.
Child actions are not allowed to perform redirect actions. Description:An unhandled exception occurred during the execution of the current web request. Review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: Child actions are not allowed to perform redirect actions.
View 4 Replies
Mar 31, 2010
My controller has a member that returns a JsonResult object, it is coded as per below. The problem is that Json(users) only returns the data from IEnumerable (MembershipUserEx objects) and I also want the data from the public Properties of MembershipUserExCollection as well. Is there a way to do this? I guess I am looking for the Json object to look something like this pseudo object:
results = {
pageIndex:0,
pageSize:50,
[code]...
View 1 Replies
Mar 6, 2011
I have some textboxes and a table of data created client side that I want pass to a controller as JSON.
I want to use Jquery to enumerate the table.
Assume I have 2 textboxes called name and age. Assume a table with 2 columns. one column with class called phonetype and one column class called phonenumber.
So how do construct the JSON from this?
View 1 Replies
Feb 8, 2011
I have the following actionresult in my controller;
[Code]....
and this jquery script to print values pass from controller in textboxes.
[Code]....
View 8 Replies
Jan 16, 2011
I am wondering if jsonResult method can be used to return Data Table? If so, is it a json array or a json string?
View 6 Replies
Apr 27, 2010
How Can we Show Data in a View By passing a jsonResult?
View 1 Replies
Mar 29, 2011
how to pass this via Json.Tried doing something like
var data = { Item1: "test", Item2: 5 };
var JSONdata = $.toJSON(data);
However that did not work. Although simply changing wcf to expect an object with two properties such as Item1 and Item2 will work. Here is example I'm using... I'll trim it a bit to make it easier to read:
function Post(data, url)
{
$.ajax({
type: 'POST',[code].....
View 1 Replies
Sep 6, 2010
I have a ASP.NET MVC 1.0 app.I have a listbox on the page and I want to pass an array to the webpage so that
javascript can use the array to do some processing depending on the item picked in the listbox.So I thought the best way is to pass JSON data to the webpage on load.So what is the best practice on how to do this?Can you please give me a brief step by step process.How do pass the array as JSON and how do I access it by index?
View 1 Replies
Feb 15, 2010
I have the following JSON class I am intending to use to perform management calls on my database asynchronously:
<script type="text/javascript">
var CalendarManager = {
defaultOptions: {
staffcode: 0, // required
date: 0, // required
[Code]....
Basically, my question is: how do I specify optional parameters to a WebMethod when providing JSON data?
I know I can reduce the parameters down to just the required values, and then use HttpContext.Request.Params to read the values of optional paramaters, but I would have thought the way I have tried here should have worked.
EDIT
The XMLHttpRequest.responseText value for the error is:
Invalid JSON primitive: staffcode.
This is throwing me even more off the scent of the problem :(
View 2 Replies
Oct 29, 2010
As it is now I create a JavaScript object and then stringify it, put it in a hidden textbox and my code behind can read this string. I then use JSON.NET to parse the string which works fine. I now try to use ajax to post it to my web service but have some issues with how to send the string. I have tried many ways but gets the common errors like
Invalid JSON primitive: myString.
So I checked this out [URL] and it works with hard coded values but I want to use a variable.
JavaScsript to create the object:
for (var i = 0; i < results.rows.length; i++) {
var row = results.rows.item(i);
var customer = new Object();
customer.id = row['id']
customer.name = row['name']
var customerString = JSON.stringify(customer);
$.ajax({
type: "POST",
url: "synchronise.asmx/synchroniseCustomers",
data: "synchroniseCustomers: " + customerString,
contentType: "application/json; charset=utf-8",
dataType: "json",
error: function (xhr, status) {
alert("An error occurred: " + status);
},
success: function (msg) {
alert("success");
}
});
}
WebMethod:
public void synchroniseCustomers(string customerString)
{
JObject o = JObject.Parse(customerString);
string id = (string)o["id"];
string name = (string)o["name"];
If I use data: '{ FirstName: "Dave", LastName: "Ward" }'
in the example above it works but I wish to pass on a string instead.
View 2 Replies
Dec 21, 2012
I've got code like this in a download page
Code:
Imports System.IO
Imports System.Data
Imports System.Data.SqlClient
Partial Class _Download
Inherits System.Web.UI.Page
[Code] .....
That is called like this:
Code:
function excelGrid(strId, blnDoReader) {
var wesPC = $("#" + strId);
var objWebParam = {};
var arrGrid = [];
[Code] ....
I am modifying this now - passing in the variable strWebParam which is the "stringified" version of a JSON array. And then in the function below I am trying to get the JSON-string into the POST. I tried the INPUT/TYPE=HIDDEN method you see below - but that did not work (cut off the string - it's got quotes in it)
Code:
$.downloadExcel = function(url, data, source, method, callback) {
var inputs = '';
var iframeX;
var downloadInterval;
if (url && data) {
[Code] ....
When I do a regular AJAX post for something I use the "data" element of the $.ajax method like this
Code:
var strWebParam = $.toJSON(objWebParam);
$.ajax({
type: "POST",
url: "WebService.asmx/BootPage",
dataType: "json",
[Code] .....
How is that DATA: STRWEBPARAM getting passed back to IIS??
View 2 Replies
Sep 10, 2012
This is regarding your article on
[URL]
I have a json object with multiple Name & Value pairs, I am using example on above given link but it is not calling the Web Method.
var jd = [];
jd.push({ ID: HArr[j], Val: Str });
var jd = [];
[Code].....
In my class I have a Web Method defined as :
[System.Web.Services.WebMethod]
public static jsonData PassJsonData(jsonData jd)
{
return jd;
}
View 1 Replies
Aug 11, 2010
I try to use the jquery + json to get all elements in form and build a JSON var to post in a ASP.NET MVC method.
[Code]....
It method get all fields in a form and build a JSON, but it dont put JSON inside JSON.
Example:
If i have the follow form:
<input name="person.name"><input name="person.age"><input name="person.address.street">
The serialized string build a JSON like this
{ "person.name": "??", "person.age": "??", "person.address.street": "??" }
I need a plugin or some function to generate like this:
{ "person": { "name" : "??", "age" : "??", "address":{ "street": "??" } } }
View 1 Replies
Dec 21, 2010
I am creating one Json array object and trying to pass it in MVC controller action method but i am getting null paramerter; as per my knowledge json only maps .net primitive datatypes.... so it assign null value.
Note: when i have look at request object i found that there are three parameter of created array. But how to get that value as parameter of function?
View 2 Replies
Jul 19, 2010
I need to log every user-action taken on a database using the username of the person logged into my ASP.net application as the identifier in the log. What is the easiest way to do this? I guess that for every method call to my data access layer I need to log the parameters of that call and the username and then call a new "log event" method that writes the details of the call to a table. Am I on the right track?
View 2 Replies