3
我使用了ng-include
,如下圖所示。但它不起作用。請告訴我爲什麼?提前致謝。Ang-ng-include與剃鬚刀頁面不兼容
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>
Soloution樹
注意:當我把它放在同一頁上,然後它工作。但我怎麼能在上面的方式做到這一點? B'cos我想將該代碼放在單獨的.cshtml
文件中。
<div ng-include="'createPropertyForm.html'"></div> //on same page where this works well
你能告訴我爲什麼這個行爲不同的* .cshtml頁面和* .html頁面?謝謝。 – Sampath
@Sampath [Anguler Docs](https://docs.angularjs.org/api/ng/directive/ngInclude),ng-include Fetches,編譯幷包含一個外部HTML片段。而cshtml是html +服務器代碼。所以首先通過mvc循環它會得到純html然後可以包含它。根據我的理解。 – Viplock
@Sampath'返回View()'或'返回PartialView()'告訴MVC生成正確的HTML並將其發回,'ng-include'可以將其添加到頁面中。希望它能幫助你。 - 謝謝 – Viplock