如何使用jscript中声明的参数调用Html.RenderAction()?
我在* .cshtml文件中有一个javascript
$(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'); } }); }); }
和控制器:
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" }; }
我想用这一行
$("#ajaxresult").html('@{Html.RenderAction("Update", "Default");}');
将ui.values[0]
和ui.values[1]
作为min
和max
参数发送到Html.RenderAction("Update", "Default")
像$("#ajaxresult").html('@{Html.RenderAction("Update", "Default", new {min = ui.values[0], max = ui.values[1]});}');
我怎么能这样做?
var url = '@Url.Action("Update", "Default")'; url += '/?min=' + ui.values[0] + '&max=' + ui.values[1]; $("#ajaxresult").load(url);
load
文档 :
描述:从服务器加载数据并将返回的HTML放入匹配的元素中。