5

I have a javascript in *.cshtml file

$(function () {

sliderDiv.slider({
  range: true,
  min: minVal,
  max: maxVal,
  values: [minVal, maxVal]
});

sliderDiv.bind("slidechange", function (event, ui) {

  var d = "min=" + ui.values[0] + "&max=" + ui.values[1];
  $.ajax({
    type: "POST",
    url: '@Url.Action("Update", "Default")',
    data: d,
    success: function (result, ajaxObj) {
        alert('ok');
        alert(result.min + " - " + result.max);
        $("#ajaxresult").html('@{Html.RenderAction("Update", "Default");}');
    },
   error: function (ajaxObj, message, exceptionObj) { alert('no'); }
});
});
}

And Controller:

public ActionResult Update(int? min, int? max)
        {
            if(min == null) min = 1;
            if(max == null) max = 1;
            var s = new SliderModel()
                                {
                                    min = (int)min * 1000,
                                    max = (int)max * 1000
                                };

            return new JsonResult
                       {
                           Data = s,
                           ContentEncoding = Encoding.UTF8,
                           JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                           ContentType = "json"
                       };

        }

I want to use this line

$("#ajaxresult").html('@{Html.RenderAction("Update", "Default");}');

to send ui.values[0] and ui.values[1] as min and max parameters to Html.RenderAction("Update", "Default")

Something like $("#ajaxresult").html('@{Html.RenderAction("Update", "Default", new {min = ui.values[0], max = ui.values[1]});}');

How can I do something like that???

tereško
  • 58,060
  • 25
  • 98
  • 150
Dmytro
  • 16,668
  • 27
  • 80
  • 130

1 Answers1

9
var url = '@Url.Action("Update", "Default")';
url += '/?min=' + ui.values[0] + '&max=' + ui.values[1];
$("#ajaxresult").load(url);

load docs:

Description: Load data from the server and place the returned HTML into the matched element.

gdoron
  • 147,333
  • 58
  • 291
  • 367