0

My question may be a duplicate of this question. But, I don't get the returned values from the view into my controller.

As defined in the link, I have a model defined for the values that are returned.

But the difference is that, I am not using the AJAX call for this. I get the values of a row, turned into an Array of values by using this stmt:

    var arrayOf = $(currentSelected).get(0);
    var partialView = ('@Url.Action("PartialView")' + '/' + arrayOf);

here partialView correctly points to my controller method and control passes there.

but, my array there (in the controller) is always showing null in spite of correct values in 'arrayOf' and that I am not able to further proceed.

Here is my controller:

     public ActionResult PartialView(ChildColumns[] arrayOf) /*arrayOf is always null, WHY*/
    {
        //stmts
        return PartialView("ChildPartialView");
    }

Here ChildColumns is the model that has all the related fields.

1
  • The razor code would execute first on the server, and then pass that information to your page where the javascript would execute. It sounds like you need to use Ajax, if you are indeed wanting to pass the javascript array to your partial view, otherwise, the partialview executes first. Commented Dec 16, 2013 at 14:35

1 Answer 1

1

I would use an ajax call for this as mentioned by CM Kanode. something like

$.ajax({
    url: "@(Url.Action("PartialView", "Controller")",
    type: "POST",
    data: arrayOf
    cache: false,
    async: true,
    success: function (result) {
        $(".divContent").html(result);
    }
});
Sign up to request clarification or add additional context in comments.

8 Comments

success: function (result)?? what should i pass as result? the controller method is acually going to return a partial view in my case.
yup, that is what you want. this will take that partial view and put it into whatever container you want. (class = divContent in my example)
My controller is fine?... should I continue to use that?
yeah, you aren't passing a model to the partial view but you may not need to. it looks good.
But if i want to return a model, what should i do?
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.