更新时间:2022-12-14 23:25:07
为 Yasser's ,但使用ngRoute:
Adding a similar answer to Yasser's, but using ngRoute:
1)而不是引用你的部分HTML,您需要将Controller / Action引用到您的ASP.NET MVC应用程序。
1) Instead of referencing your partial HTML, you need to reference a Controller/Action to your ASP.NET MVC app.
.when('/order', {
templateUrl: '/Order/Create',
controller: 'ngOrderController' // Angular Controller
})
2)您的ASP.NET MVC将返回.cshtml查看:
2) Your ASP.NET MVC will return a .cshtml view:
public class OrderController : Controller
{
public ActionResult Create()
{
var model = new MyModel();
model.Test= "xyz";
return View("MyView", model);
}
}
3)你的MyView.cshtml会混合使用Razor和Angular 。注意:作为Angular应用程序的一部分,将布局设置为null。
3) Your MyView.cshtml will mix Razor and Angular. Attention: as its a partial for your Angular app, set the layout as null.
@model MyProject.MyModel
@{
Layout = null;
}
<h1>{{ Test }}</h1> <!-- Angular -->
<h1>Model.Test</h1> <!-- Razor -->