0

I have a class in my server-side code, say, something like this:

public class foo
{
   public int FieldOne { get; set; }
   public string FieldTwo { get; set; }
   public float FieldThree { get; set; }
}

Now, in my client-side code, there's a form that loads data in inputs that are meant to be used to retrieve information from the database, and then that information has to be loaded to a jqGrid.

I know how to get the server-side function/action the data from the form if it's in the form of a [HttpPost], something like:

[HttpPost]
public ActionResult Index (foo model)
{
   ...
}

But I can't get the grid to call this method. I have set the parameter "url" of jqGrid to "Controller/Index", but it doesn't call it.

Is there anyway to call it that way? Or is there any other way I can send the form information in object format through Javascript?

Thanks.

UPD:

This is the grid code:

grid.jqGrid({
        url: "Controller/Action",
        datatype: 'json',
        emptyrecords: "No hay proyectos cargados",
        colNames: ['Code', 'Desc', 'Rev', 'Client'],
        colModel: [
                 { name: 'Code', index: 'Code', width: 100 },
                 { name: 'Desc', index: 'Desc asc, Desc', width: 200 },
                 { name: 'Rev', index: 'Rev', width: 100, align: "right" },
                 { name: 'Client', index: 'Client', width: 200, align: "right" }
               ],
        rowNum: 10,
        loadonce: false,
        sortname: 'Code',
        viewrecords: true,
        sortorder: "desc",
        height: 'auto',
        caption: ""
    });

It's the same if I change the URL for the one generated by @Url.Action().

4
  • try sth like this '@Url.Action("Index")' and please paste your grid code. Commented Aug 21, 2012 at 15:19
  • 1
    Please have a look on this question: stackoverflow.com/questions/4063682/… Commented Aug 21, 2012 at 15:36
  • do u get any error in firebug, developer tools, fiddler? Commented Aug 21, 2012 at 16:21
  • Thanks nemesv, that will do it. Commented Aug 21, 2012 at 17:18

1 Answer 1

1

Add this line in your Grid.

mtype: 'GET'

Right now your grid is trying a GET (default) request for a POST only action (due to the attribute you applied). Alternatively, you can remove the POST restriction and add the AllowGet option to your return Json(*******).

There might be more then one problem but let's start with the easy stuff :)

-Edit-

Also, as mentioned in comments, Fiddlers + Firebugs/Chrome console helps a LOT when working with javascript / ajax / json since they do not output anything visual when there are errors.

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

1 Comment

Well, actually I solved it using the postData option, and an action that returned a string through a JavaScriptSerializer object. Thank you anyway

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.