Angular ng-include 不适用于 razor 页面
Angular ng-include is not working with the razor page
我用过ng-include
如图below.But不是working.Could你告诉我为什么?提前致谢。
createOrEditPropertyModal.cshtml
<div ng-include="'propertymanagement/tabs/createPropertyForm.html'"></div>
我试过这种方法also.But同样404
错误。
<div ng-include="'tabs/createPropertyForm.html'"></div>
createPropertyForm.cshtml
<script type="text/ng-template" id="createPropertyForm.html">
<form name="createPropertyForm" role="form">
//removed for clarity
</form>
</script>
解决方案树
注意 : 当我把它放在同一页上时 works.But 我怎样才能用上面的方法做到这一点?因为我想将该代码放在单独的 .cshtml
文件中。
<div ng-include="'createPropertyForm.html'"></div> //on same page where this works well
方法一:OP的回答
你可以做 this.Here 是 way.You 必须给出完整路径,如下所示。
<div ng-include="'~/App/tenant/views/propertymanagement/tabs/createPropertyForm.cshtml'"></div>
如果您有任何性能问题,请在此处查看:
方法二:
您不能使用 ng-include
包含 .cshtml 页面
为此你必须使用正确的 mvc 路由,比如
<div ng-include="'controller/Template/createPropertyForm'"></div>
这里的 createPropertyForm 就像是 action 方法的 id 部分
public ActionResult Template(string id)
{
switch (id.ToLower())
{
case "createPropertyForm":
return PartialView("~/Views/propertymanagement/tabs/createPropertyForm.cshtml");
default:
throw new Exception("template not known");
}
}
否则只需创建一个 html 页面并以
访问它
<div ng-include="'createPropertyForm.html'"></div>
我用过ng-include
如图below.But不是working.Could你告诉我为什么?提前致谢。
createOrEditPropertyModal.cshtml
<div ng-include="'propertymanagement/tabs/createPropertyForm.html'"></div>
我试过这种方法also.But同样404
错误。
<div ng-include="'tabs/createPropertyForm.html'"></div>
createPropertyForm.cshtml
<script type="text/ng-template" id="createPropertyForm.html">
<form name="createPropertyForm" role="form">
//removed for clarity
</form>
</script>
解决方案树
注意 : 当我把它放在同一页上时 works.But 我怎样才能用上面的方法做到这一点?因为我想将该代码放在单独的 .cshtml
文件中。
<div ng-include="'createPropertyForm.html'"></div> //on same page where this works well
方法一:OP的回答
你可以做 this.Here 是 way.You 必须给出完整路径,如下所示。
<div ng-include="'~/App/tenant/views/propertymanagement/tabs/createPropertyForm.cshtml'"></div>
如果您有任何性能问题,请在此处查看:
方法二:
您不能使用 ng-include
包含 .cshtml 页面为此你必须使用正确的 mvc 路由,比如
<div ng-include="'controller/Template/createPropertyForm'"></div>
这里的 createPropertyForm 就像是 action 方法的 id 部分
public ActionResult Template(string id)
{
switch (id.ToLower())
{
case "createPropertyForm":
return PartialView("~/Views/propertymanagement/tabs/createPropertyForm.cshtml");
default:
throw new Exception("template not known");
}
}
否则只需创建一个 html 页面并以
访问它 <div ng-include="'createPropertyForm.html'"></div>