使用 jquery 获取部分视图并更新 UI
我需要渲染部分视图(从控制器返回)以显示一些客户摘要详细信息。当用户单击按钮时,需要发生这种情况。同时,用户可以在网格上选择不同的客户。我在网格选择更改事件上使用 jquery 记下隐藏字段中选定的客户 ID。当用户单击按钮时,我需要将此隐藏字段值(选定的 id)传递给控制器,控制器会执行一些工作并返回部分视图。然后我需要在页面上呈现这个部分视图。我已尝试以下操作,但有两个问题
- 我无法弄清楚如何将隐藏字段值发送到控制器
- 渲染部分视图后,如果用户选择另一个客户并再次单击按钮,我无法重新渲染
它代码:
#PlaceHolder is just a div element
function DoSomwWork() {
$('#PlaceHolder')
.load('<%= Url.Action("GetSelectedCustSummary",
"SomeController",
new { selectedId = **HIDDEN FIELD VAL HERE** })%>');
}
}
I need to render a partial view (returned from the controller) to show some customer summary details. This will need to happen when the user clicks on a button. In the the mean time the user can select different customers on a grid. I keep note of the selected customer id in a hidden field using jquery on the grids selection changed event. When the user clicks on a button i need to pass this hidden field value (selected id) to the controller, the controller does some work and returns a partial view. I then need to render this partial view on the page. I have tried the following but have two problems
- I cant fig out how to send the hidden field value to the controller
- After the partial view is rendered I cant get it to rerender if the user selects another customer and clicks the button again
The code:
#PlaceHolder is just a div element
function DoSomwWork() {
$('#PlaceHolder')
.load('<%= Url.Action("GetSelectedCustSummary",
"SomeController",
new { selectedId = **HIDDEN FIELD VAL HERE** })%>');
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我怀疑你能以这种方式做到这一点。
然而,由于您已经在使用 MVC,您应该能够定义一个操作(在您的情况下为“GetSelectedCustSummary”)并返回一个 json 对象,然后使用 jQuery
更新操作它:
定义操作方法,如下所示:
然后在 Jquery 中调用您的操作方法:
每次单击更新按钮时,分配所需的 id,然后触发 Jquery 函数。
它在我的项目中对我有用
I doubt you will be able to do it this way.
However since you are already using MVC, you shall be able to define a action ("GetSelectedCustSummary"in your case) and return a json object instead, then manipulate it with your jQuery
Update:
Define Action Method something like:
then call your Action Method in Jquery:
Every time you click update button, assign the id you want, and trigger the Jquery function.
It worked for me in my project