问题描述
我正在与 angular 作斗争,以使其包含 ng-view 之外的部分 cshtml 视图.
这是我的主要观点:
<div class="header"><div class="loginView"><div ng-include="主页/模板/登录"></div>
我正在与 angular 作斗争,以使其包含 ng-view 之外的部分 cshtml 视图.
这是我的主要观点:
<div class="header"><div class="loginView"><div ng-include="主页/模板/登录"></div>
<div class="容器"><div ng-view></div>
这是我的部分 Login.cshtml:
<div class="form-group"><input type="text" name="loginName" class="form-control input-sm" placeholder="Brugernavn" oninvalid="this.setCustomValidity('Indtast brugernavn')" ng-model="UserData.LoginName" ng-required="true"></div><div class="form-group"><input type="text" name="password" class="form-control input-sm" placeholder="Kodeord" oninvalid="this.setCustomValidity('Indtast kodeord')" ng-model="UserData.Password" ng-required="true"></div><div class="form-group"><button class="btn btn-primary btn-sm" ng-click="Login()" ng-disabled="login.password.$error.required || login.loginName.$error.required">登录<;/按钮>
</表单>
我使用 mvc 返回调用 url 的特定部分视图,如下所示:
public ActionResult Template(string id){开关 (id.ToLower()){案例登录":return PartialView("~/Views/Account/Partials/Login.cshtml");案例注册":return PartialView("~/Views/Account/Partials/Register.cshtml");案例主要":return PartialView("~/Views/Main/MainPage.cshtml");默认:throw new Exception("模板未知");}}
基本上我相信 ng-include 应该调用 url ,它将返回 html ,该 html 将被包含在页面上.但这不是发生的事情,根本没有调用模板方法.我当然可以在母版页上包含整个模板,但稍后登录后我想用登录的用户数据模板替换这个模板.
知道如何解决这个问题吗?
ng-include 对表达式求值,确保如果您要直接加载路径,请使用两组引号.
<div ng-include="'Home/Template/login'"></div>
Im fighting with angular to make it ng-include a partial cshtml view outside of ng-view.
here is my main view:
<div class="container">
<div class="header">
<div class="loginView">
<div ng-include="Home/Template/login"></div>
</div>
</div>
</div>
<div class="container">
<div ng-view></div>
</div>
here is my partial Login.cshtml:
<form name="login" ng-controller="LoginCtrl" class="form-inline">
<div class="form-group"><input type="text" name="loginName" class="form-control input-sm" placeholder="Brugernavn" oninvalid="this.setCustomValidity('Indtast brugernavn')" ng-model="UserData.LoginName" ng-required="true"></div>
<div class="form-group"><input type="text" name="password" class="form-control input-sm" placeholder="Kodeord" oninvalid="this.setCustomValidity('Indtast kodeord')" ng-model="UserData.Password" ng-required="true"></div>
<div class="form-group">
<button class="btn btn-primary btn-sm" ng-click="Login()" ng-disabled="login.password.$error.required || login.loginName.$error.required">Login</button>
</div>
</form>
im using mvc to return specific partial views on calls to url like this:
public ActionResult Template(string id)
{
switch (id.ToLower())
{
case "login":
return PartialView("~/Views/Account/Partials/Login.cshtml");
case "register":
return PartialView("~/Views/Account/Partials/Register.cshtml");
case "main":
return PartialView("~/Views/Main/MainPage.cshtml");
default:
throw new Exception("template not known");
}
}
basicly i would belive that ng-include should call url which will return html to which will be inculded on a page. But thats not what happend, Template method is not called at all. I could ofcourse include whole template on master page, but later on after login i want to replace this template with logged in user data template.
Any idea how to fix this?
ng-include evaluates an expression, make sure if you're looking to load a path directly you use two sets of quotation marks.
<div ng-include="'Home/Template/login'"></div>
这篇关于Angular ng-include cshtml 页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!