在 ASP.NET MVC 中,如何最好地设计/编码的异步部分回发
在窗体中包含的 MVC 视图 (.aspx) 上,有多个控件(网格、文本框),用于显示与主题(人员)相关的数据。该表单不需要提交按钮,因为绝大多数数据仅供查看。但是,有一个显示注释的网格(Telerik MVC)。用户应该能够在文本框中添加评论,然后该评论应该出现在网格中。由于评论数据来自两个不同的数据库源并合并在存储过程中,因此我无法使用内联网格编辑。
问题 1.
是否可以将包装 DIV 的内容(即带有新注释的文本框)异步回发到控制器,而无需完整的表单回发和页面闪烁?
谢谢,
阿诺德
On a MVC View (.aspx) enclosed in a Form, there are several controls - grids, textboxes - that display data relating to a subject, a person. The form does not require a submit button because the great majority of data is for viewing only. However, there is a grid (Telerik MVC) that displays comments. A user should be able to add a comment - in a textbox - and that comment should then appear in the grid. Because the comments data comes from two different database sources and are merged in a stored procedure, I'm not able to use inline grid editing.
Question 1.
Is it poossible to asynchronously postback the just contents of the wrapping DIV - i.e. the textbox with the new comment - to a controller without a complete Form postback and page flicker?
Thanks,
Arnold
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以制作一个按钮,通过使用单击按钮时发生的 jQuery / JavaScript post 函数,将文本框的内容(新注释)“提交”到控制器操作。
然后,控制器操作可以将新评论存储在特定数据库中,如果您在此之后添加“成功”方法,则只需调用 ajaxRequest() 即可刷新网格。
希望这有帮助。
You could make a button that would "submit" the contents of the text box (the new comment) to a Controller Action by using a jQuery / JavaScript post function that occurs when clicking the button.
The controller action could then store the new comment in the specific database and if you add a "success" method after that occurs you could just call an ajaxRequest() to refresh the grid.
Hope this helps.
是的,这是可能的。我们以下面的表单为例,您只想发布第二个 DIV:
并且您可以发送如下 AJAX 请求:
Yes it is possible. Let's take as an example the following form where you want to post only the second DIV:
and you could send an AJAX request like this: