레이아웃이없는 Razor보기
Layout = null;
내 뷰에 있을 때 어떻게 -여전히 기본 레이아웃을 가져 옵니까 ?!
그것을 막을 수있는 트릭이 있습니까?
레이아웃이없는 내보기는 다음과 같습니다.
@{
Layout = "";
}
<!DOCTYPE html>
<html>
<head>
<title>Index</title>
@{Html.RenderAction("Head", "Header");}
</head>
<body>
<div>
Home
</div>
</body>
</html>
다음은 렌더링 된 출력입니다 !!
<!DOCTYPE html>
<html>
<head>
<title>Index</title>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<link href="/Content/Site.css" rel="stylesheet" type="text/css" />
<script src="/Scripts/jquery-1.5.1.min.js" type="text/javascript"></script>
<script src="/Scripts/modernizr-1.7.min.js" type="text/javascript"></script>
</head>
<body>
header
</body>
</html>
</head>
<body>
<div>
Home
</div>
</body>
</html>
이 디렉토리에 _viewstart.cshtml이 있습니까? _viewstart를 사용하려고 할 때 겪었던 동일한 문제가 발생했습니다. 그런 다음 이름을 _mydefaultview로 변경하고 views / shared 디렉토리로 이동 한 다음 원하지 않는 cshtml 파일에보기를 지정하지 않고 나머지는 _mydefaultview를 지정하는 것으로 전환했습니다. 이것이 왜 필요한지 모르지만 효과가있었습니다.
나는 이것을 생각 해요 :
@{
Layout = "";
}
다음과 같지 않습니다.
@{
Layout = null;
}
두 번째를 사용하고 작동하며 _Viewstart가 포함되어 있지 않습니다.
당신 (그리고 KMulligan)은 _ViewStart
페이지를 오해하고 있습니다.
_ViewStart
것입니다 항상 페이지가 시작되기 전에 실행합니다.
속성 (예 :)을 초기화하는 데 사용됩니다 Layout
. 일반적으로 마크 업을 포함해서는 안됩니다. (재정의 할 방법이 없기 때문에).
올바른 패턴은를 호출하는 별도의 레이아웃 페이지를 만들고 에서이 페이지를 가리 키도록 속성을 RenderBody
설정하는 것 Layout
입니다 _ViewStart
.
그런 다음 Layout
콘텐츠 페이지 를 변경할 수 있으며 변경 사항이 적용됩니다.
나는 그것이 개별 "보기"로 작업하는 것이 더 낫다고 생각한다. 나는 PHP에서 MVC4로 옮기려고 노력하고있다. 정말 힘들지만 올바른 길을 가고있다.
질문에 답하고, 개별 페이지를 작업하려면 _ViewStart.cshtml을 편집하십시오.
@{
Layout = null;
}
CSS 경로에 문제가있는 경우 또 다른 팁 ...
URL 앞에 "../"를 넣으십시오.
This are the 2 problems that i get today, and I resolve in that way!
Regards;
Logic for determining if a View should use a layout or not should NOT be in the _viewStart
nor the View
. Setting a default in _viewStart
is fine, but adding any layout logic in the view/viewstart prevents that view from being used anywhere else (with or without layout).
Your Controller Action should:
return PartialView()
By putting this type of logic in the View you breaking the Single responsibility principle rule in M (data), V (visual), C (logic).
Use:
@{
Layout = null;
}
to get rid of the layout specified in _ViewStart.
I wanted to display the login page without the layout and this works pretty good for me.(this is the _ViewStart.cshtml file) You need to set the ViewBag.Title in the Controller.
@{
if (! (ViewContext.ViewBag.Title == "Login"))
{
Layout = "~/Views/Shared/_Layout.cshtml";
}
}
I know it's a little bit late but I hope this helps some body.
Procedure 1 : Control Layouts rendering by using _ViewStart file in the root directory of the Views folder
This method is the simplest way for beginners to control Layouts rendering in your ASP.NET MVC application. We can identify the controller and render the Layouts as par controller, to do this we can write our code in _ViewStart file in the root directory of the Views folder. Following is an example shows how it can be done.
@{
var controller = HttpContext.Current.Request.RequestContext.RouteData.Values["Controller"].ToString();
string cLayout = "";
if (controller == "Webmaster") {
cLayout = "~/Views/Shared/_WebmasterLayout.cshtml";
}
else {
cLayout = "~/Views/Shared/_Layout.cshtml";
}
Layout = cLayout;
}
Procedure 2 : Set Layout by Returning from ActionResult
One the the great feature of ASP.NET MVC is that, we can override the default layout rendering by returning the layout from the ActionResult. So, this is also a way to render different Layout in your ASP.NET MVC application. Following code sample show how it can be done.
public ActionResult Index()
{
SampleModel model = new SampleModel();
//Any Logic
return View("Index", "_WebmasterLayout", model);
}
Procedure 3 : View - wise Layout (By defining Layout within each view on the top)
ASP.NET MVC provides us such a great feature & faxibility to override the default layout rendering by defining the layout on the view. To implement this we can write our code in following manner in each View.
@{
Layout = "~/Views/Shared/_WebmasterLayout.cshtml";
}
Procedure 4 : Placing _ViewStart file in each of the directories
This is a very useful way to set different Layouts for each Controller in your ASP.NET MVC application. If we want to set default Layout for each directories than we can do this by putting _ViewStart file in each of the directories with the required Layout information as shown below:
@{
Layout = "~/Views/Shared/_WebmasterLayout.cshtml";
}
Just create the view as a partial view so that no layout file is used.
참고URL : https://stackoverflow.com/questions/6613626/razor-view-without-layout
'Program Tip' 카테고리의 다른 글
Github : gh- 페이지를 마스터로 미러링 (0) | 2020.11.09 |
---|---|
TextView의 텍스트 기본 색상은 무엇입니까? (0) | 2020.11.09 |
특정 필드 값을 기준으로 먼저 정렬 (0) | 2020.11.09 |
SQL Server® 2016 Express 전체 다운로드 (0) | 2020.11.09 |
Mac OS X에서 터미널 창에 코드를 vim에 붙여 넣기 (0) | 2020.11.09 |