tags:

views:

41

answers:

2

Hi,

I am working on my first MVC application and am running into a bit of a problem. I have a data table that when a row is clicked, I want to return the detail from that row. I have a function set up as:

function rowClick(item)
{
    $("#detailInfo").data("width.dialog", 800); 
    $.ajax({
        type: "GET",
        contentType: "application/json; charset=utf-8",
        url: "<%= Url.Action("GetDetails", "WarningRecognition")%>",
        data: "",
        dataType: "json",
        success: function(data) {//do some stuff...and show results}
 }

The problem I am running into is the passing of the "item". I calls the Controller function that looks like this:

public JsonResult GetDetails(string sDetail)
    {
        Debug.WriteLine(Request.QueryString["sDetail"]);
        Debug.WriteLine("sDetail: " + sDetail);
        var myDetailsDao = new WarnRecogDetailsDao();

        return new JsonResult { Data = myDetailsDao.SelectDetailedInfo(Convert.ToInt32(sDetail)) };
    }

But it never shows anything as the the "sDetail". It does hit the function but nothing is passed to it.

So, I have read where you pass the parameter via the data but I have tried every combination I can think of and it never shows up. Tried:

data: {"item"} data: {sDetail[item]} data: {sDetail[" + item + "]}

Any help is greatly appreciated. Thanks in advance.

Geo...

A: 

Did you try { sDetail: item }? The data item name needs to match the action argument or asp.net mvc won't know how to wire things up properly.

R0MANARMY
Yes I tried that but it still does not show in the COntroller as anything passed to it.
George
@George: Can you post the URL that your get request generates?
R0MANARMY
Not sure I understand what you want me to post.
George
@George: The `$.ajax(...)` call generates an HTTP GET request, I want you to post the URL of that get request.
R0MANARMY
Sorry if I am not understand but in the code I wrote, the $.ajax call is calling the Controller:public JsonResult GetDetails(string sDetail) { Debug.WriteLine(Request.QueryString["sDetail"]); Debug.WriteLine("sDetail: " + sDetail); var myDetailsDao = new WarnRecogDetailsDao(); return new JsonResult { Data = myDetailsDao.SelectDetailedInfo(Convert.ToInt32(sDetail)) }; }
George
@George: I understand it calls the controller, what URL does it use to get there?
R0MANARMY
url: "<%= Url.Action("GetDetails", "WarningRecognition")%>",
George
Found the answer: url: "<%= Url.Action("GetDetails", "WarningRecognition")%>?sDetail=" + item,
George
A: 

All i know is the format must be:

var data = '{"sDetail":"item"}';

It doesn't look like your data is in the format. Have you tried that combination?

Joseph Connolly
Yes tried that but still nothing is passed to controller.
George