ASP.NET MVC 2 - 如何让 Ajax.BeginForm 在部分视图中正常工作
我有一个带有 url 的视图
/Home/SetResults?patentId=[somePatientId]
,它的一部分得到有条件的ajax更新,并使用一些partialview
在该partialView内部,我有这段代码
<% using (Ajax.BeginForm("Action", "Home", new AjaxOptions { UpdateTargetId = "placeholder", InsertionMode = InsertionMode.Replace,HttpMethod = "Post"}))
{%>
<div id="placeholder">
....
每当我按下提交按钮时,我都会进入我的简单控制器操作方法
[HttpPost]
public ActionResult Action(MyModel model)
{
return PartialView();
}
除了ajax之外,一切都正常本身 - 我总是重定向到带有 url 的视图,而不是使用控制器操作的结果更新我的占位符
/主页/操作
那么,是否可以部分更新部分视图?如果是的话我做错了什么?
I have a View with url like
/Home/SetResults?patientId=[somePatientId]
, part of it gets conditionaly ajax-updated with some partialview
Inside of that partialView I have this code
<% using (Ajax.BeginForm("Action", "Home", new AjaxOptions { UpdateTargetId = "placeholder", InsertionMode = InsertionMode.Replace,HttpMethod = "Post"}))
{%>
<div id="placeholder">
....
Whenever I press submit button I get to my simple controller action-method
[HttpPost]
public ActionResult Action(MyModel model)
{
return PartialView();
}
Everything works fine except the ajax itself - instead of gettin my placeholder updated with the result of controller action I'm always getting redirect to a view with the url of
/Home/Action
So, is it possible to partially update partial view? If yes what I'm doin wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
需要检查的一件事是您是否包含 ajax 脚本:
我注意到如果不包含该脚本,提交 Ajax 表单的行为就像常规提交一样。
One thing to check would be that you are including the ajax script:
I've noticed if this isn't included, submitting the Ajax form behaves like a regular submit.