ASP.NET MVC查询字符串不正确 [英] MVC ASP.NET querystring incorrect
本文介绍了ASP.NET MVC查询字符串不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我和我的查询字符串的一个问题,我叫一个动作在我的控制器像这样的JavaScript
I have a problem with my querystring, i call an action in my controller with javascript like this
if ((event >= 65) && (event <= 90) || (event >= 48) && (event <= 57)) {
var focussed = document.activeElement.id;
window.setTimeout(function () {
alert(in2.value);
location.href = "/CarSaldi/ListaArt?in1=" + in1.value + "&in2=" + in2.value + "&focus=" + focussed;
}, 1000);
}
IN2是一个输入文本,并可能有一个+里面(例如,牛奶+巧克力),当我打电话的动作在我的控制器
in2 is a input text and might have a "+" inside it (for example "milk+chocolate"), when i call the action in my controller
public ActionResult ListaArt(string in1, string in2, string cod, string focus)
{
[...]
}
字符串IN2显示我的牛奶巧克力,我预计牛奶巧克力+ ...我也需要有+里。
the string in2 shows my "milk chocolate", i expected milk+chocolate...i need to have also the "+" inside.
推荐答案
您应该使用Java脚本函数连接codeURIComponent
为en code网址。
You should use java script function encodeURIComponent
to encode url.
location.href = "/CarSaldi/ListaArt?in1=" + encodeURIComponent(in1.value)
+ "&in2=" + encodeURIComponent(in2.value) + "&focus=" + encodeURIComponent(focussed);
您需要更改code如下:
You need to change you code as follows
if ((event >= 65) && (event <= 90) || (event >= 48) && (event <= 57)) {
var focussed = document.activeElement.id;
window.setTimeout(function () {
alert(in2.value);
location.href = "/CarSaldi/ListaArt?in1=" + encodeURIComponent(in1.value)
+ "&in2=" + encodeURIComponent(in2.value) + "&focus=" + encodeURIComponent(focussed);
}, 1000);
}
这篇关于ASP.NET MVC查询字符串不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文