views:

289

answers:

2

I have the following in partial view

<%= Ajax.ActionLink("Plunder Again", "Resources", new { controller = "Resource", parent = Model.ToJson() }, new AjaxOptions { UpdateTargetId = Model.ResourceType })%>

going to the controller method:

    public ViewResult Resources(/*ModelResource parent*/)
    {
        Debug.Assert(Request.Params["parent"]!=null);
        var jss=new System.Web.Script.Serialization.JavaScriptSerializer();
        var parent=jss.Deserialize<ModelResource>(Request.Params["parent"]);
        return View(parent.PlunderAmount);
    }

but it throws an exception because the json doesn't properly pass via url, it can't find the 'Type' parameter.

I tried simply having the ModelResource as a parameter to the Action but it came in as null

This action will also be returning a partial view if that matters in any way.

A: 

ActionLink is used to create an anchor to a URL -- the URL must be valid! In general, you don't pass a whole object to an Action because the route values have to be bound back into the model and passed to the action. You might pass an ID of object though so the Action can get the object using that key.

statichippo
A: 

If you want to send Model to controller instead of Ajax.ActionLink use Ajax.BeginForm

ali62b
so I can send data that way without it going in the url?
Maslow
Yes using Ajax.BeginForm the page is not post back nor you need a link just data behind the scene posts to server and response back.
ali62b