[英]Angular ng-include is not working with the razor page
I have used ng-include
as shown below.But it is not working.Could you tell me why ? 我使用了
ng-include
,如下所示。但它没有用。你能告诉我为什么吗? Thanks in advance. 提前致谢。
createOrEditPropertyModal.cshtml createOrEditPropertyModal.cshtml
<div ng-include="'propertymanagement/tabs/createPropertyForm.html'"></div>
I have tried this way also.But same 404
error. 我也试过这种方式。但同样的
404
错误。
<div ng-include="'tabs/createPropertyForm.html'"></div>
createPropertyForm.cshtml createPropertyForm.cshtml
<script type="text/ng-template" id="createPropertyForm.html">
<form name="createPropertyForm" role="form">
//removed for clarity
</form>
</script>
Soloution Tree Soloution树
Note : When I put it on the same page then it works.But how can I do that in above way ? 注意:当我把它放在同一页面上然后它工作。但我怎么能以上述方式做到这一点? B'cos I would like to put that code on separate
.cshtml
file. B'cos我想将该代码放在单独的
.cshtml
文件中。
<div ng-include="'createPropertyForm.html'"></div> //on same page where this works well
Method 1 : OP's Answer 方法1:OP的答案
You can do this.Here is the way.You have to give the full path as shown below. 你可以这样做。这就是方法。你必须给出如下所示的完整路径。
<div ng-include="'~/App/tenant/views/propertymanagement/tabs/createPropertyForm.cshtml'"></div>
If you have any performance issues then check it out here : ng-Include is very slow with the external template 如果您有任何性能问题,请在此处查看: ng-Include与外部模板的速度非常慢
Method 2 : 方法2:
you cant include .cshtml page by using ng-include 你不能使用ng-include包含.cshtml页面
for it you have to go with proper routing of mvc ,Like 对于它你必须适当的路由mvc,喜欢
<div ng-include="'controller/Template/createPropertyForm'"></div>
here createPropertyForm will be like a id part of a action method 这里createPropertyForm将像一个动作方法的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");
}
}
otherwise just create a html page and access it as 否则只需创建一个html页面并将其作为
<div ng-include="'createPropertyForm.html'"></div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.