角NG-包括CSHTML页 [英] Angular ng-include cshtml page
问题描述
林的战斗具有角,使其NG-包括NG-视图外的部分CSHTML视图。
Im fighting with angular to make it ng-include a partial cshtml view outside of ng-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>
这是我的部分Login.cshtml:
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>
使用MVC来返回调用特定的部分景色给url这样的即时通讯:
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我会相信的是NG-包括应该叫URL将返回的HTML,将页面上进行inculded。但那不是发生了什么,模板方法完全不叫。我可以ofcourse包括母版页上整个模板,但后来登录后我要替换此模板登录的用户数据模板。
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-包括计算一个前pression,确保如果你正在寻找直接使用两套引号加载的路径。
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>
这篇关于角NG-包括CSHTML页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!