使用angular 2应用程序在ASP.NET核心MVC中导入MVC模型类 [英] Importing MVC model class in ASP.NET core MVC with angular 2 application

查看:96
本文介绍了使用angular 2应用程序在ASP.NET核心MVC中导入MVC模型类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





是否可以将在Models文件夹中创建的模型类(例如product.cs)导入到角度2应用程序中在product.ts文件下创建相同的字段并在Asp.NET Core Angular 2应用程序中使用它?



是否有任何重用代码的解决方案而不是创建2个相同领域的课程?



我尝试过:



我创建了一个打字稿文件,它包含在模型类(* .cs)下可用的相同字段并在应用程序上工作。

解决方案

你也可以不导入任何内容,并使用动态类型来获取值。大多数情况下,当您不了解服务器上的模式实现时,您可以轻松使用这些类型而不是模仿类型。



我在C#上写了一篇关于JSON的文章,有人问这个问题,你可以在这里阅读更多关于这个主题的文章,Re:你将如何反序列化这个例子? [ ^ ]。



通过动态,我的意思是跳过类型检查,并将其推迟到运行时,然后访问对象,如果它们不是

Hi,

Is it possible to import a model class(let's say product.cs) which is created in "Models" folder into the angular 2 application instead of creating the same fields under product.ts file and using it in the Asp.NET Core Angular 2 application?

Is there any solution for reusing the code instead of creating 2 classes with same fields?

What I have tried:

I have created a typescript file which consists of same fields which are available under model class(*.cs) and worked on the application.

解决方案

You can also "not" import anything at all, and use dynamic types to get the values. Most of the times when you have no idea about the schema implementations on the server, then you can easily use these types instead of mimicking the types.

I wrote an article about JSON with C#, there this kind of question was asked, you can read more on that topic here, Re: How you will Deserialize this example? [^].

By dynamic, what I mean is to "skip" type checking, and defer it until the runtime and then access the objects if they are not null.


这篇关于使用angular 2应用程序在ASP.NET核心MVC中导入MVC模型类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆