Skip to main content

Posts

Showing posts from July, 2015

asp.net mvc different between ViewComponent Html.Partial Html.Action

asp.net mvc ViewComponent Html.Partial Html.Action的区别 mvc4及以前,通常使用Html.Partial("viewName"),Partial函数的返回值为MvcHtmlString,直接输出在Rozar模版中。 Html.RenderPartial("viewName")的返回值是void,输出内容流中。 查看mvc5的源代码发现Partial也是调用RenderPartial,然后输出到TextWriter来转换为字符串。 上面两个不用controller,不通过action。 Html.Action的返回值PartialView(),通过调用action来获取PartialView。 例如,通过ajax调用action来更新客户端Partial输出的内容。 mvc5中新增的ViewComponent,所有的都由ViewComponent继承而来。总体来说可认为是一个增强版Partial。 能有自己单独的代码文件,又不用的实现controller。 ref: http://www.cnblogs.com/gesenkof99/archive/2013/06/03/3115052.html http://stackoverflow.com/questions/29823507/why-should-we-use-mvc-6-feature-view-components-over-partial-view-what-is-the-d http://www.tugberkugurlu.com/archive/exciting-things-about-asp-net-vnext-series-mvc-view-components