从 JQuery Autocomplete 插件将参数传递给 ASP.Net MVC2 Action
我使用以下代码将 2 个硬编码参数传递给 ASP.Net MVC2 控制器操作:
<script type="text/javascript">
$(document).ready(function () {
$("form#search_for_entity_user input#term").autocomplete({
source: '<%= Url.Action("GetEntitySharedUsers", "Search") %>',
delay: 200,
minLength: 3,
select: function (event, ui) {
$.post('<%= Url.Action("AddSharedUser", "Entity", new { id = "42", snlid="17394" }) %>',
function (data) { })
}
});
});
</script>
这工作正常,但现在我需要更改 $.post 中传入的值以来自我的模型,所以我在想一些事情就像下面的代码一样,但这不起作用。关于如何解决这个问题有什么想法吗?
<script type="text/javascript">
$(document).ready(function () {
$("form#search_for_entity_user input#term").autocomplete({
source: '<%= Url.Action("GetEntitySharedUsers", "Search") %>',
delay: 200,
minLength: 3,
select: function (event, ui) {
$.post('<%= Url.Action("AddSharedUser", "Entity", new { id = '<%= Model.EntityId %>', name= '<%= Model.Name %>' }) %>',
function (data) { })
}
});
});
</script>
I'm passing 2 hardcoded parameters to an ASP.Net MVC2 Controller Action with this code:
<script type="text/javascript">
$(document).ready(function () {
$("form#search_for_entity_user input#term").autocomplete({
source: '<%= Url.Action("GetEntitySharedUsers", "Search") %>',
delay: 200,
minLength: 3,
select: function (event, ui) {
$.post('<%= Url.Action("AddSharedUser", "Entity", new { id = "42", snlid="17394" }) %>',
function (data) { })
}
});
});
</script>
This works fine, but now I need to change the values passed in in the $.post to come from my Model, so I'm thinking something like the following code, but that doesn't work. Any ideas on how to fix this?
<script type="text/javascript">
$(document).ready(function () {
$("form#search_for_entity_user input#term").autocomplete({
source: '<%= Url.Action("GetEntitySharedUsers", "Search") %>',
delay: 200,
minLength: 3,
select: function (event, ui) {
$.post('<%= Url.Action("AddSharedUser", "Entity", new { id = '<%= Model.EntityId %>', name= '<%= Model.Name %>' }) %>',
function (data) { })
}
});
});
</script>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个怎么样?
不过,如果是我,我会提取该数据,使其更具语义:
How about this?
If it were me, though, I would extract that data so it is more semantic: