gpt4 book ai didi

c# - 如何使用 jscript 中声明的参数调用 Html.RenderAction()?

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:36:20 27 4
gpt4 key购买 nike

我在 *.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'); }
});
});
}

和 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"
};

}

我要用这条线

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

ui.values[0]ui.values[1] 作为 minmax 发送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 docs :

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

关于c# - 如何使用 jscript 中声明的参数调用 Html.RenderAction()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10897433/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com