javascript 如何使用在 jscript 中声明的参数调用 Html.RenderAction()?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10897433/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to call Html.RenderAction() with parameters declarated in jscript?
提问by Dmytro
I have a javascript in *.cshtml file
我在 *.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'); }
});
});
}
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")
发送ui.values[0]
和ui.values[1]
作为min
和max
参数Html.RenderAction("Update", "Default")
Something like $("#ajaxresult").html('@{Html.RenderAction("Update", "Default", new {min = ui.values[0], max = ui.values[1]});}');
就像是 $("#ajaxresult").html('@{Html.RenderAction("Update", "Default", new {min = ui.values[0], max = ui.values[1]});}');
How can I do something like that???
我怎么能做这样的事情???