【发布时间】:2012-11-09 07:20:25
【问题描述】:
我想将 textarea 值和其他一些参数传递给 action 方法。所以我按照以下方式使用了jquery。
查看:-
@Html.TextArea("aboutme")
<a id="@Profile.Id" title="@Profile.name" onclick="SubmitProfile(this)" >
Submit</a>
jquery方法:-
function SubmitReview(e,count) {
var Text = "'"+jQuery("#aboutme").val()+"'";
var url = 'http://' + window.location.host + '/Controller/ActionMethod?' + 'id=' + e.id + '&name=' + e.title + '&aboutme=' + Text;
jQuery("#Profile").load(url);
}
操作方法:-
public ActionResult ActionMethod(string id,string name,string aboutme)
{
//
}
上面的代码工作正常,但是当任何一个参数值包含 空格 时。在 Jquery 方法中,URL 看起来不错。但在 action 方法中,它将值修剪到第一个空格,其余参数为空。
让我用一些例子来解释
假设 id='123',name='amith cho' ,aboutme='我是软件工程师'
Jquery 方法中的 URL
url='http://localhost/Controller/ActionMethod?id=123&name=amith cho ,aboutme=i am software engg'
但它正在作为id=123 name=amith aboutme=null 采取行动方法
如何解决?
【问题讨论】:
-
使用此 URL
http://localhost/Controller/ActionMethod?id=123&name=amith cho ,aboutme=i am software engg将数据发送到操作是 bad、bad、bad做法...改为发布这些值。
标签: jquery asp.net-mvc-3 url asp.net-mvc-routing