ASP.Net MVC 中的渲染视图
在我的代码中,我使用部分视图(称为 PV1)
<div id="div_1">
<% Html.Partial("PV1", Model); %>
</div>
,在该部分视图中,我使用“Ajax.BeginForm”将其重定向到特定操作,因此它正在这样做......
using (Ajax.BeginForm("action1", "Forms", null, new AjaxOptions { UpdateTargetId = "div_1" }, new { id = "form1" }))
{
Response.write("I am here.");
}
public ActionResult action1(XYZ Model)
{
//
return PartialView("PV1", Model);
}
在操作的最后一行我我再次调用相同的部分“PV1”,因此它也在执行此操作...
但是在渲染视图时,它不会打印或执行部分视图中编写的步骤,它会覆盖它们并且不显示任何内容...
In my code I am using a partial view (call it PV1)
<div id="div_1">
<% Html.Partial("PV1", Model); %>
</div>
and in that partial view I am using "Ajax.BeginForm" to redirect it to a particular action, hence it is doing so ...
using (Ajax.BeginForm("action1", "Forms", null, new AjaxOptions { UpdateTargetId = "div_1" }, new { id = "form1" }))
{
Response.write("I am here.");
}
public ActionResult action1(XYZ Model)
{
//
return PartialView("PV1", Model);
}
at the last line of action I am again calling the same partial 'PV1', hence it is doing this too ...
but when rendering the view it don't print or do the steps written with in partial view, it override them with and show nothing ...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Html.Partial 实际上返回渲染视图的结果,您想要执行
<%= Html.Partial() %>
或<% Html.RenderPartial(); %>
Html.Partial()
返回 Html,因此必须通过<%= %
> 在页面上输出Html.RenderPartial()
使用 Response.Write 输出到页面上,并且可以与<% %>
一起使用。Html.Partial actually returns the result of rendering the view, you want to do
<%= Html.Partial() %>
or<% Html.RenderPartial(); %>
Html.Partial()
returns the Html and thusly must be output on the page via<%= %
> andHtml.RenderPartial()
uses Response.Write to output onto the page and can be used with<% %>
.这不是您使用 Ajax.BeginForm 的目的。该帮助器用于创建实际的
我不太清楚你想要实现什么目标。如果你想使用 ajax 加载部分视图,我建议使用类似 jQuery 的 ajax load 方法。
This is not what you would use
Ajax.BeginForm
for. That helper is used to create actual<form>
tags that will later be submitted to the server using MVC's unobtrusive ajax (so you still need some kind of a trigger action - a button, javascript - anything that submits the form).I'm am not very clear on what you're trying to achieve. If you want to load a partial view with ajax, I would suggest using something like jQuery's ajax load method.