开发者

Generic view in razor

开发者 https://www.devze.com 2023-01-28 00:31 出处:网络
Good morrow, I am learning about razor, and found myself stuck in a problem. Although i know how to use inheritance with cshtml file with an actual class, \"@inherits BasicListView<UserModel>\

Good morrow,

I am learning about razor, and found myself stuck in a problem.

Although i know how to use inheritance with cshtml file with an actual class, "@inherits BasicListView<UserModel>", I wanted to have all the comodities of 开发者_如何学运维the cshtml template engine, to make a base view, like a generic listing view, per instance.

I believe that one might not be able to directly, cshtml to cshtml, mark an inheritance, but it is quite ok, as it will become a class anyway.

As well, i could generate the class by myself and then use it's object, i may be wrong, but sounds a little too workaround for me.

Would anyone care of having an elegant solution for it?

Edit: I will redo the question:

Keeping in mind that there is a strongly-typed view, for per example a list page, can anyone think on how to implement a generic-typed view, for the same porpouse?


Well, you're view would either need to work off a common interface e.g.

@inherits BasicListView<IMyModel>

Or use dynamic:

@inherits BasicListView<dynamic>
0

精彩评论

暂无评论...
验证码 换一张
取 消