在ASP.Net MVC渲染视图 [英] Rendering view in ASP.Net MVC

查看:164
本文介绍了在ASP.Net MVC渲染视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的code我用的是局部视图(称之为PV1)

In my code I am using a partial view (call it PV1)

<div id="div_1">
    <% Html.Partial("PV1", Model); %>
</div>

和在局部视图我使用Ajax.BeginForm来重定向到一个特定的动作,因此,它是这样做的......

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);
}

在动作我再次调用相同的部分'PV1',最后一行因此它被太这样...

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 ...

推荐答案

Html.Partial实际上返回渲染视图的结果,你想要做的&LT;%= Html.Partial()%GT ; &LT;%Html.RenderPartial(); %GT;

Html.Partial actually returns the result of rendering the view, you want to do <%= Html.Partial() %> or <% Html.RenderPartial(); %>

Html.Partial()通过&LT返回HTML正是如此,必须在页面上输出>>和 Html.RenderPartial()使用的Response.Write输出到页面上,可以用&LT使用;%%GT;

Html.Partial() returns the Html and thusly must be output on the page via <%= %> and Html.RenderPartial() uses Response.Write to output onto the page and can be used with <% %>.

这篇关于在ASP.Net MVC渲染视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆