Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3975368
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T04:40:36+00:00 2026-05-20T04:40:36+00:00

I have a partial view with this jquery script: $(#btnGetEmpInfo).click(function () { var selectedItem

  • 0

I have a partial view with this jquery script:

$("#btnGetEmpInfo").click(function () {
          var selectedItem = $('#EmployeeId').val();
          var focusItem = $('#EmployeeId')
      alert("Starting");
          $.ajax({
            type: "GET",
            contentType: "application/json; charset=utf-8",
            url: "<%= Url.Action("getEmpInfo", "NewEmployee")%>?sData=" + selectedItem,
            data: "{}",
            success: function(data) {
                if (data.length > 0) {
                alert("Yeah!");
                } else {
                   alert("No data returned!");
                }
              }                   
            });
            alert("Back!");
      });  

Then in my controller I have:

 [AcceptVerbs(HttpVerbs.Get)]
    public JsonResult getEmpInfo(string sData)
    {
        return new JsonResult { Data = "test" };
    }

I can breakpoint in the controller and it is hitting, but the only “Alerts” I get are the “Starting” and “Back”. Why would the data not be returned or at least hit saying no data returned?

Thanks in advance for any and all help.

Geo…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T04:40:37+00:00Added an answer on May 20, 2026 at 4:40 am

    You probably might want to improve this ajax call like this:

    $.ajax({
        type: 'GET',
        url: '<%= Url.Action("getEmpInfo", "NewEmployee")%>',
        data: { sData: selectedItem },
        success: function(data) {
            // Warning: your controller action doesn't return an array
            // so don't expect a .length property here. See below
            alert(data.Data);
        }                   
    });
    

    and have your controller action accept GET requests:

    [AcceptVerbs(HttpVerbs.Get)]
    public JsonResult getEmpInfo(string sData)
    {
        return Json(new { Data = "test" }, JsonRequestBehavior.AllowGet);
    }
    

    OK, now that we have fixed the error let me elaborate. In your code you were using an application/json content type to format your request string. Unfortunately in ASP.NET MVC 2 there is nothing out of the box that is capable of making sense of JSON requests (unless you wrote a custom json value provider factory). Then using string concatenation to append the sData parameter to the URL without ever URL encoding it meaning that your code would break at the very moment the user enters some special character such as & in the EmployeeId textbox.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have jquery code that is being reused by a repeatable partial view on
I am using jQuery.load() to render a partial view. This part looks like this:
How can I have a view render a partial (user control) from a different
I have this partial code: if ($getRecords = $con->prepare(SELECT * FROM AUCTIONS WHERE ARTICLE_NO
I have a partial view that I am using from 2 different forms. In
I have a partial view where I render, if the user has choosen an
I have a controller action which renders a partial view: public ActionResult Details(int id)
I have found this example on StackOverflow: var people = new List<Person> { new
I have my main view like this: <%@ Page Title= Language=C# MasterPageFile=~/Views/Shared/Site.Master Inherits=System.Web.Mvc.ViewPage %>
I think this is a common scenario - I have a view where I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.