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 bu开发者_开发知识库t 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 + "]}
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.
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?
精彩评论