.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
Kaviya Balasubramanian
Imran Ghani
Post New Web Links

JSON data disappears on call

Posted By:      Posted Date: October 12, 2010    Points: 0   Category :ASP.Net
 

Hey

I have a problem with a AJAX call I do in a application.
It's a MVC application (ASP.net c#) with a lot of javascript.

When I do a call from my javascript to a controller (through a ajax call) the call gets to the class and function, but the data isn't there.
The data is send in JSON.

I found a few of the same problem but most of the time they used another name voor de parameter then it is in there json. That's not my problem.

Here is the code

$.ajax({
            type: "POST",
            url: "/Event/Home/UserInfo",
            data: jsonString,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (result) {
               //RESULT
            },
            error: function (xhr, msg, e) {
                //ERROR
            }
});

public JsonResult UserInfo(string json)
 {
            DateTime theDate = DateTime.Parse(json);
            int HomeTimeZoneIndex = VisitContext.TimezoneIndex;
            double HomeTimeZoneOffset = TzConvert.ToLocalExt(theDate, VisitContext.TimezoneIndex).Offset.TotalMinutes;
            string PublicName = VisitContext.PublishMember.PublicName;
            string Id = VisitContext.PublishMember.ID.


View Complete Post


More Related Resource Links

WCF Data Service to JSON example? v4

  

I would like to take WCF Data Service and produce JSON output to consume on various mobile apps.

Can anyone give me a how-to on the JSON part?  I.e., what is different than normal XML outut?


Thanks.

 


Writing Data to database with jQuery Forms, ASMX Webservice, & JSON - help!

  

Hi, 

Can someone point me in the right direction on how to submit data from a jQuery form to a ASMX webservice? I have gotten everything on the form ready to be submitted to the database and now I am stuck on how to send it over using $.ajax(). Everything I have read tells me how to get data from a webservice and display it with jQuery, but not the other direction nor how to access the json data within the within the webservice service(similar to a Request.Form approach with ASP.NET forms).

In other words: 

1. What do I need to do to my webservice to make sure it can receive data from the jQuery form. 

2. What do I need to do in jQuery to receive an acknowledgement the save on the server side was successful. 

I can explain more if need be, but if there is a comprehensive tutorial on not only reading, but also WRITING data with jQuery, JSON, etc. I would love to get pointed in that direction. 


make json call to send an email

  

the aspx:

<div class="contactSubmit">
                <asp:ImageButton ID="ibSubmit" runat="server" ValidationGroup="vgContact" /></div>


 

the jquery :

$(document).ready(function () {
            // Add the page method call as an onclick handler for the div.
            $(".contactSubmit").click(function () {
                $.ajax({
                    type: "POST",
                    url: "Home.aspx/GetDate",
                    data: "{}",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (msg) {
                        // Replace the div's content with the page method's return.
                        $(".contactSubmit").text(msg.d);
                    }
                });
            });
        });


The problem is that I need to use the text in a text box in my webmethod, and I can't because it's static, this results in a compilation error:

[WebMethod]
    public static string SendContactForm()
    {
        Mail.SendMailMessage(NameTextBox.Text);
    }

<

Parameter Data changing between DataSource_Inserting and the BLL call

  


Hi,

I have a problem when trying to validate data on insertion (and possibly update, didnt try it yet) .


I use a formview in insert mode, linking to a custom BLL that then link to a DAL to insert data into a table. The problem is the parameter data is changing between the Datasource inserting event and when the BLL insert method is called. 2 field, that cannot be null in the database, have default value added to them. Bot sure how to explain so well so 'ill post some picture explaining :


This is the form I use, I enter only test in the textbox for the value Nom


this is the trace for my DataSource_Inserting event, as you can see, only the "Nom" value is non-null


But then, right after the event is done and the call is made to the BLL, the value for "Sexe" and "DateDeNaissance" has been changed to some default value, namely 0 and Jan 1, year 1.



This of course is causing problem because if the user does not provide value for "Sexe" and "DateDeNaissance" then I want t

IE 8 partially cut of my JSON data return from WCF service

  
Hi All, I am not so sure here is the right place to post my issue. I am using ExtJS treepanel and ajax call to wcf webservice and return JSON array. My service return array. If array count is less than 2, then IE partially cut of my JSON data return from WCF service. But FireFox is working fine with same JSON format string. Very interesting thing is that I try to debug with Fildder. so I have to put "." dot in my url "http://localhost{.}:1234/ then It is working fine.   I am testing with IE8. Here is the JSON format return from FF and FireBug. {"result":[{"href":"..\/EMP\/EmployeeSearch.aspx","iconCls":"","id":"8c362443-7bb3-427e-910c-87b391c6abf5","leaf":true,"text":"Employees"}]} Here is the corrupted JSON string retrun from IE using developer tool. {"result":[{"href":"..\/EMP\/E" [OperationContract] [WebInvoke(Method = "POST", UriTemplate = "GetSiteMap", BodyStyle = WebMessageBodyStyle.Wrapped, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)] [return: MessageParameter(Name = "result")] List<TreeView> GetSiteMap(string node);

Getting data out of objects in a JSON response

  
I'm working on an MVC2 site that needs to update the values of a select list based on the value selected by a user in another list. This is the response I'm getting from my controller's JSON action: [{"Selected":false,"Text":"Client1Group1","Value":null},{"Selected":false,"Text":"Client1Group2","Value":null}] The problem is that the data object my function gets back is a collection of generic objects. When the following script runs I get two alerts, but instead of getting the Text value from my objects I get "undefined".var clients = $("#properties_ClientList");var groups = document.getElementById("properties_GroupList");//User selects a client nameclients.change(function() {    //Clear group SelectList    $('#properties_GroupList option').each(function(i, option){ $(option).remove(); });    //Repopulate group SelectList    $.getJSON("<%=Url.Content("~/Admin/GetGroupSelectListForReportEditViewAsJsonResult")%>", { clientId: clients.val() },        function(data) {            $.each(data, function(){                

Web Service and JSON input data

  
Hy, I'm try to build a web service who can get in input a JSON string. My web method is: [WebMethod(Description = "Edit Entity")][System.Web.Script.Services.ScriptMethod(ResponseFormat = System.Web.Script.Services.ResponseFormat.Json)]public string ManageEntity(string _DataIn){ // System.Diagnostics.Debug.WriteLine(_DataIn);            return "{\"Result\":\"OK\"}";} When I try posting some data to the webservice I get the error "No parameterless constructor defined for type of 'System.String'". Why the system try to deserialize my JSON string? Is possible to simple retrieve the string? Thanks Lorenzo SonciniLorenzo Soncini

consuming wcf Data service in different format in client - SOAP (including a WDSL), XML, JSON, etc.

  
Hi I have implemented wcf data service with entity framework with the following steps, i want to know i can we consume this WCF Data service in different format like (SOAP, JSON, XML, PLIST). it will be helpfull if some one help on this. - Created web application with VS2010 and added edmx file and selected tables,views and SPs that i want to use - imported SP with complex type by using function import. - Created WcfDataservice (.svc File). - in SVC File i have added [webget] method as follows.         [WebGet]        public List<GetSearchResultWithComplextype_Result> GetSearchResultComplextype(string email, string Title, string Color)        {            Entities db = new Entities();            var query = db.GetSearchResultWithComplextype(email, Title, Color);            List<GetSearchResultWithComplextype_Result> caseList = query.ToList<GetSearchResultWithComplextype_Result>();            return caseList;        } - created one more client application and added service reference. here i want to cons

consuming wcf Data service in different format in client - SOAP (including a WDSL), XML, JSON, etc.

  
Hi  I have implemented wcf data service with entity framework with the following steps, i want to know i can we consume this WCF Data service in different format like (SOAP, JSON, XML, PLIST). it will be helpfull if some one help on this. - Created web application with VS2010 and added edmx file and selected tables,views and SPs that i want to use - imported SP with complex type by using function import. - Created WcfDataservice (.svc File). - in SVC File i have added [webget] method as follows.         [WebGet]         public List<GetSearchResultWithComplextype_Result> GetSearchResultComplextype(string email, string Title, string Color)         {             Entities db = new Entities();             var query = db.GetSearchResultWithComplextype(email, Title, Color);             List<GetSearchResultWithComplextype_Result> caseList = query.ToList<GetSearchResultWithComplextype_Result>();             return caseList;         } - created one more client application and added service reference. here i wan

Error (no data returned) when ResponseFormat:=WebMessageFormat.Json and attempting to serialize an I

  

I have am having an issue when attempting to return JSON data from a WCF Service.  I have tracked the issue down to the ResponseFormat:=WebMessageFormat.JSON, but I am unable to make any further progress.  

 

I am wanting the return types of my service to be an interface so that I have a little more control over the responses that are coming to my application.  

I know that returning an interface requires the ServiceKnownType and requires KnowsType on the objects so that they can serialize properly.  I have an example working, however, when add a property with a class that inherits from iList things go bad.  The service returns nothing.  I have confirmed via Fiddler that the content-length of the response is 0.  However if I switch the ResponseFormat to WebMessageFormat.XML it works fine and all objects are returned.  I have included as much code (and probably more) as I think is necessary.  If something else is needed, let me know. 

Any insight is greatly appreciated.

 

Code Notes:

If you comment out the DataMember Attribute on the Values property in TestResult class you will see that the code works perfectly when returning JSON. 

If you change the return Type of the Values Property to be TestCollection instead of ITestCollection it works as well.  

Templating for Json in an AJAX call

  

Hi,

I am new and working on JQuery. I been looking around for templating in ASP.NET.

Suppose I have Json data coming from web service in an AJAX call. Is there any way to use that in Template and than fill that template at the required place?

Any good approach.


Thanks



using jsonresult actions to pass json data to 3rd party apps

  

hello,

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 JSonResult

How can i test the output of this URL to ensure the JSON is properly formed..

OR

must my URL be in the format http://www.abc.com/controller/action.json?


Thanks



asynchronous call for data population in user control

  

i have a user control in which i want  to populate a drop down on blur event of text box asynchronously.. i tried with page method but it gives error as method is undefined.. then i tried with writing a web service..
and called a web service method in javascript on user control.. this also gives the same error as method is undefined...project is using master pages.. so the script manager is registered in master page..
so i added service reference as



ScriptManager sm = ScriptManager.GetCurrent(this.Page);
            sm.Services.Add(new ServiceReference("../Controls/MeetingTime.asmx"));

in user control...


below is my javascript call..

function getMeetingTime()
    {       
        
       var uclcmbUserId = document.getElementById('<%= uclcmbActiveClients.ClientID %>'+'<%= uclcmbActiveClients.ActualComboId%>');       
        
        try
        {   
        
   &

Problem filling labels with table data outside datalist using single call to db

  

On a single page, I'd like to fill 2 hyperlink controls as well as a datalist control with table data using one call to the database. The page looks like this:

<div id="PageContent">    
    <h2>
      Districts</h2>
    <p>
      Please select the district you wish to view below.</p>
    <p>
      <asp:DropDownList ID="ddlDistrict" runat="server" CssClass="textbox" 
        DataTextField="DistrictName" DataValueField="DistrictId" AutoPostBack="True" 
        onselectedindexchanged="ddlDistrict_SelectedIndexChanged">
      </asp:DropDownList>
    </p>    
    <p><asp:label ID="lblDistrictAbbrev" runat="server" Text="District Abbreviation: " />
      <asp:hyperlink ID="hyperlinkDistrictName" runat="server" 
        Text='' NavigateUrl="~/Contact/NationalCouncil.aspx" 
        Font-Bold="True" />
    </p>
    <p><asp:label ID="lblDistrictCouncillor" runat="server" Text="District Councillor: " />
      <asp:hyperlink ID="hyperlinkCouncillor" runat="server" 
        Text='' NavigateUrl="~/Contact/NationalCouncil.a

Make a C# WinForm Call a JS code in a Data server??!!

  
Hi... 
I have a situation as follows:
My company has its Customers Data stored in a server, and we as employees use Internet Explorer to find the data needed through a page that contains some textboxes to supply info to the server and some other textboxes that shows Data retrieved from server. So fro example I put the customerID in a textbox, press the search button near this textbox, and I get the customerName and customerAge and so on in another textboxes in the same webpage. I konw this is done via JavaScripts.

I hope the scene is clear, Now when I need to print a report about certain customer I have to copy/paste every single textbox content to Word individually.

So I know how to export from C# to Word or at least to Excel .., But is it possible to make a C# WinForms App that can read the contents of these textboxes OR call the JS function that is executed when I press the (Search) button shown in the IE WebPage.

I dont know if my question is clear enough but I hope you can help me. Any help would be appreciated.
Thanks in advance

Using WebGet to read JSON data from CouchDB.

  

I have a CouchDB database that I'm attempting to read data from using WebGet.  I'm using the following code and configuration:

WCF service and data contract:

  [ServiceContract]
  interface IBaseBallContract
  {
    [OperationContract]
    [WebGet(UriTemplate = "/baseball/{id}")]
    TeamDocument GetDocument(string id);
  }

  [DataContract()]
  class TeamDocument : IExtensibleDataObject
  {
    [DataMember(Name = "TeamName")]
    public string TeamName { get; set; }

    [DataMember(Name = "State")]
    public string State { get; set; }

    public ExtensionDataObject ExtensionData { get; set; }
  }

Client code:

ChannelFactory<IBaseBall

Design Data Contract for User Create/Update/Delete REST API using WCF 3.5 & JSON

  

Hi,

I'm using REST with WCF .NET 3.5. I've design the class structure with below JSON struvture of input & output.

API 1: Create User: POST /id & request body is as shown below:

{
  "userList" :
   [
    {
       "name" : "<name>",
       "email" : "<email>",
       "dataId" : <dataId>,
       "country" : "<country code>",
    },
    {
       "name" : "<name>",
       "email" : "<email>",
       "dataId" : <dataId>,
       "country" : "<country code>",
    }
   ]
}

The response object should be as shwon below:

{
  "userCreateResults" :
   [
    {
       "email" : "<email>",
       "userId" : <userId>,
       "password" : "<password>",
       "result" : <result code>
    },
    {
       "email" : "<email>",
       "userId" : <userId>,
       "password" : "<password>",
       "result" : <result code>
    }
   ]
}

API 2: Update User: PUT /id & request body is as shwon below:

{
  "userList" :
   [
    {
       "userI
Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend