A
A
Alyosha2018-03-06 21:58:36
ASP.NET
Alyosha, 2018-03-06 21:58:36

Is it possible to use multiple models on one cshml page?

I am writing in ASP.NET Core 2 MVC.
For example, I connect the model to the cshtml page.
@model Название проекта.Models.Название модели
And then in the code I use the data received from the model
@Html.Raw(Model.Переменная)
. Is it possible to use, for example, 2 or 3 or more models on one cshtml page? And How? After all, the Model method by default will work for the first connected model.
Or get data from other tables using ajax ?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
E
eRKa, 2018-03-06
@kttotto

No. You need several models - encapsulate into one, the facade is called.

C
cicatrix, 2018-03-07
@cicatrix

Not at all, but if you really want to, you can if you use partial view.
Each partial view can use its own model.
In the code of the main View you do Html.RenderPartial.
Strictly speaking, these are, of course, different cshtml, but practically the result is the same as for one.

D
Dmitry Bashinsky, 2018-03-07
@BashkaMen

Alternatively, use a collection of models

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question