开发者

How to pass parameters while calling controller's function using jquery

I am using below function to call a function on controller:

  function getPartialView(actionUrl, targetDiv, ajaxMessage, callback) {
        showAjaxMessage(targetDiv, ajaxMessage);

        $.get(actionUrl, null, function (result) {
            $(targetDiv).html(result);
            callback();
        });
    }

and calling it like this:

  getPartialView("UCDamage", "#dvdamageAreaMid", "Loading...", function () { });

this fun开发者_C百科ction provides me facility just like updatePanel in classic asp.net web forms. now please tell me how can i pass values in function as a parameter.

actually the UCDamage is a user control which will be randered in div:dvdamageAreaMid. the code is written on current form on which i am displaying this userControl named "UCDamage". but i need to pass some values to this function in controller.

my controller function is like this:

  public ActionResult UCDamage(string searchText)
    {           
        SecureModelService service = new SecureModelService();
        return View(service.ListBodyWork(searchText));
    }

i have tried with taking textbox with namex searchText and retrieve its value but not able to get it.

Please provide me some suggestion and help me out. Thanks


You can pass values to your controller via the second parameter in your $.get call. Something along the lines of

$.get(actionUrl, { searchText: "hello world" }, function (result) {
        $(targetDiv).html(result);
        callback();
    });

The jQuery documentation has some examples on how to do this: http://api.jquery.com/jQuery.get/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜