1

here is my project hirarchy:

enter image description here

from browser.js I'm trying to call ManagerController:

 $("#jstree").jstree({
        "json_data": {

    "ajax": {   


                type: "GET",
                async: true,
                "url": "Controllers/Manager/Getlocations?userId='1234'",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                cache: false,
                success: function (msg) {                         
                        return msg;
                },
                error: function () {
                    // TODO process error
                }
            },

//continuation is less relevant

But I get the following error in chrome console:

GET http://localhost:1186/MainUgi/Controllers/Manager/Getlocations?userId='1234'&_=1324071607446 404 (Not Found)

1) what should be the right path ?

2) what is the &_=1324071607446 which is concatinated to the end of my get request?

update

my controller looks like:

  public class ManagerController : Controller
    {

        public JsonResult GetLocations(string userId)
        {
            var locationsJson = 
            new {[  {"data": "[0]", .. some data...}  ]};

            return Json(locationsJson, JsonRequestBehavior.AllowGet);
        }

my request looks like:

Request URL:http://localhost:1186/MainUgi/Controllers/Manager/Getlocations?userId=1234
Request Method:GET
Status Code:404 Not Found
Request Headersview source
Accept:application/json, text/javascript, */*; q=0.01
Accept-Charset:windows-1255,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:he-IL,he;q=0.8,en-US;q=0.6,en;q=0.4
Connection:keep-alive
Content-Type:application/json; charset=utf-8
Host:localhost:1186
Referer:http://localhost:1186/MainUgi/browser.htm
User-Agent:Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.63 Safari/535.7
X-Requested-With:XMLHttpRequest
Query String Parametersview URL encoded
userId:1234
Response Headersview source
Cache-Control:private
Connection:Close
Content-Length:2346
Content-Type:text/html; charset=utf-8
Date:Fri, 16 Dec 2011 22:00:37 GMT
Server:ASP.NET Development Server/10.0.0.0
X-AspNet-Version:4.0.30319

TIA

3 Answers 3

2

The basic MVC url mask is the following:

/{CONTROLLER}/{ACTION}?{...PARAMETERS}

By your example we have:

'/manager/getLocations?userId=1234'

And the controller should have the following code (example):

[ControllerAction]
public void getLocations( int userId ) {
    ViewData["UserId"] = userId;
    RenderView("GetLocations");
}

Now you need to have a view file to show the content. Create a folder (inside the root of the project), named "View", and inside it, create another one with the name of the controller (Manager), and create a view file called "GetLocations.aspx" (the one that we want asked to render).

To print the UserId variable in the view:

<%= ViewData["UserId"] %>

If it doesn't work, it's better for you to read a lot about the MVC Pattern. You can start here.

Sign up to request clarification or add additional context in comments.

2 Comments

I'm trying to use the contoller as webService only. Not the whole MVC pattern
I did. but I'll recheck on that
2

Hopefully this will help:

  1. Try removing the single quotes from userId='1234' --> userId=1234
  2. The _=1324071607446 parameter is jQuery appending a timestamp to the end of the request URL to prevent caching (notice how you've used cache: false).

Comments

0

Try separating the url and the data into two separate commands:

url:  "Controllers/Manager/Getlocations",
data: { userId: '1234' }

Also try marking the method as [HttpGet] in case you have that method overloaded.

1 Comment

I don'r have overload and I use GET so I'm not sure the splitting will work. I'll try

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.