views:

1093

answers:

1

Hi

I'm currently loading a view(ascx) into a div using jQuery load(). I want to pass some variables to the view when loading it though so i'm using $.load(view, data); This does not seem to cause any problems but i have no idea how to access the Json object i'm passing in to the control.

Here is the jQuery:

var val = {"Id":"1"};
$("#DynamicForm").empty().load('/controller/view', val);
+1  A: 

In this case jQuery issues a POST request:

POST /controller/view HTTP/1.1
...

Id=1

So, you can access the Id parameter as Request.Form["Id"], or just as an action parameter:

public class Controller...
{
    public ActionResult Index(string Id) { ... }
}
DreamSonic
This answer is correct.But I found that if you're relying on Json returned from asp.net "return Json(Id=1)" you need to parse the object through the Json plugin to convert it back to the correct object format. $.evalJSON(val)
Webmonger