Skip to main content

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

Comments

Popular posts from this blog

Google Notebook整合了Google 书签

FF上一直装有Google笔记本的插件,一直没有到一面上去看,今天无意点到。发现多了个叫“Unfiled”的记事本,记得自己并未建过这么个东西,进去一看才发现,其实就是我的Google书签: 并且右下角也多了“Labels”,且与我Google书签中的相同。 其实人家的右上角的“ New features! ”里说得很清楚: Integration with Google Bookmarks Notebook is now integrated with Google Bookmarks. Your bookmarks will show up as a special Unfiled notebook, making Google Notebook a single place to collect and organize interesting web pages. To publish and collaborate, just drag and drop bookmarks into notebooks.

PSP 三国无双 大蛇传 人物图片

PSP三国无双 大蛇传 人物图片(Google Picasa相册) 现在还不全,太多了。。。(2008-03-23) 搞完了,体力活啊。(2008-04-20) 暂时放弃吧,那个空间到期很久了,忘了更新这里了。什么时候找到地方放再跟新。(2009-04-29) 上传到Google Picasa(2009-09-25)

调用Response.Redirect时出现ThreadAbortException

调用Response.Redirect("test.aspx")时出现ThreadAbortException异常,是因为在内部调用Response.End(),而Response.End() 方法终止页的执行,并将此执行切换到应用程序的事件管线中的Application_EndRequest 事件。不执行 Response.End 后面的代码。可以使用 Response.Redirect ("test.aspx", false); 来代替。 更多情况请参考 PRB:在使用 Response.End、Response.Redirect或Server.Transfer时出现ThreadAbortException 适用于.net framework 1.0 1.1