将视图转换为局部视图 [英] Convert Views to Partial Views
问题描述
我在Visual Studio中通过单击鼠标右键=>添加=>视图创建了一些视图. 我在选择中选择:使用布局或母版页". 现在,我想将这些视图变成部分视图,是否应该删除它并创建新视图?还是可以以某种方式将其变成部分视图而不删除视图?
I created some views in visual studio by clicking right click=> add => view. I select in the selection: "use a layout or master page". Now I want to turn these views to partial views should I delete it and create new? or I can somehow turning it to partial view without deleting the views?
推荐答案
在Razor中,View
和partial view
没有太大区别
唯一的区别是
In Razor there is no much difference in View
and partial view
Only difference is
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
如果未指定布局,则可以将它们视为局部视图.
If there is no layout specified they could be considered as partial views.
从您的控制器操作中返回PartialView();而不是返回View();此布局将不会应用.
From your controller action you return PartialView(); instead of return View(); this layout will not be applied.
这篇关于将视图转换为局部视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!