0

How can i pass parameters to a partial view using jquery method .load() , i have this function

 var str;
    var x;
    x = $("#whereQuery");
    str = x.attr("value");
    $("#btnSearch").click(function () {
        $('#budgetsKey').dialog({
            modal: true,
            title: "Clave presupuestal de ingresos",
            width: 550,
            minWidth: 400,
            maxWidth: 650,
            show: "slide",
            hide: "slide",
            draggable: false,
            resizable: false,
            open: function(event, ui) {
            //Load the CreateAlbumPartial action which will return 
            // the partial view _CreateAlbumPartial
            $(this).load("@Url.Action("Prueba2")", { str: str});
        }

        });
        return false;
    });
});

and in my controller i have this

 public PartialViewResult Prueba2(String str)
    {
        List<PTI_IncomeBudgetTransference> incomeBudgetTransferenceList;
        cmp_Company = this.masterService.company.GetById(1);
        //Recupera las cuentas por pagar por autorizar
        incomeBudgetTransferenceList = siagService.incomeBudgetTransference.GetAll(this.cmp_Company.CMP_ID, "Pendiente de Autorización");
        return PartialView("Prueba2", incomeBudgetTransferenceList);
    }

and i need that "str" to execute a query in my controller, but how can i send it to my action

3 Answers 3

2

You should do this in your open handler

$(this).load('@Url.Action("Prueba2", new { str = str})');
Sign up to request clarification or add additional context in comments.

7 Comments

can you try with = instead of : in the routevalues object?
Noup i try, and still nothing
I just tried loading som content to a div on a click using $("#aaaaa").load('@Url.Action("Index", new { str= "something"})'); and it worked just fine.
Hey man this is working, but when i try to pass the value of this str = x.attr("value"); i do this: $(this).load('@Url.Action("Prueba2", new { str= str})'); and this: $(this).load('@Url.Action("Prueba2", new { str= x.attr("value")})'); but doesnt work
try x.val() if it is a jquery object
|
2

This Would be work too.

`$("#divForPartialView").load("/HelloWorld/GetAwesomePartialView",
  { param1: "hello", param2: 22},function (){/do other cool client side stuff}

);`

Comments

1

It works only if you know the string, in my case string is a client side variable so I change the code into as follow and it worked:

$(this).load('@Url.Action("Prueba2"') + '/' + str);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.