如何使用JScript中declarated参数调用Html.RenderAction()? [英] How to call Html.RenderAction() with parameters declarated in jscript?
问题描述
我在* .cshtml文件中的JavaScript
$(函数(){sliderDiv.slider({
范围:真,
分:MINVAL,
马克斯:MAXVAL,
值:[MINVAL,MAXVAL]
});sliderDiv.bind(slidechange功能(事件,UI){ 变种D =分钟=+ ui.values [0] +与&最大=+ ui.values [1];
$阿贾克斯({
键入:POST,
网址:'@ Url.Action(更新,默认),
数据:D,
成功:函数(结果,ajaxObj){
警报('OK');
警报(result.min + - + result.max);
$(#ajaxresult)HTML('@ {Html.RenderAction(更新,默认);}')。
},
错误:功能(ajaxObj,消息,exceptionObj){警报('无'); }
});
});
}
和控制器:
公众的ActionResult更新(INT?分钟,诠释?最大值)
{
如果(分== NULL)分= 1;
如果(最大== NULL)最大= 1;
变种S =新SliderModel()
{
分=(INT)分钟* 1000,
最大值=(int)的最大值* 1000
}; 返回新JsonResult
{
数据= S,
ContentEncoding = Encoding.UTF8,
JsonRequestBehavior = JsonRequestBehavior.AllowGet,
的ContentType =JSON
}; }
我想使用此行
$(#ajaxresult)HTML('@ {Html.RenderAction(更新,默认);}');
发送 ui.values [0]
和 ui.values [1]
为分
和最大
参数 Html.RenderAction(更新,默认)
类似 $(#ajaxresult)。HTML('@ {Html.RenderAction(更新,默认,新的{分钟= ui.values [0],最大= UI .values [1]});}');
我怎么可以这样做在于:
VAR URL ='@ Url.Action(更新,默认)';
URL + ='/分钟='+ ui.values [0] +'和;最大='+ ui.values [1];
$(#ajaxresult),负载(URL)。
负荷
文档 :
描述:加载来自服务器的数据,并将返回的HTML到匹配元件。
块引用>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]
andui.values[1]
asmin
andmax
parameters toHtml.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???
解决方案var url = '@Url.Action("Update", "Default")'; url += '/?min=' + ui.values[0] + '&max=' + ui.values[1]; $("#ajaxresult").load(url);
Description: Load data from the server and place the returned HTML into the matched element.
这篇关于如何使用JScript中declarated参数调用Html.RenderAction()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!