Contributor
2990 Points
855 Posts
May 07, 2020 12:23 PM|YihuiSun|LINK
Hi, Baze72
Depending on your needs, you can use Tuple so that you can use two models from different database on one page.
I make a simple example, you can refer to it.
Controller
private ManagerContext db = new ManagerContext(); private ManagerContextTwo db2 = new ManagerContextTwo(); // GET: TwoDatabase public ActionResult Index() { TestUser testUser = db.TestUsers.Find(1); ImageModel imageModel = db2.ImageModels.Find(1); var tuple = new Tuple<TestUser, ImageModel>(testUser, imageModel); return View(tuple); }
Page
@using yihuisunMVC.Models; @model Tuple<TestUser, ImageModel> @{ ViewBag.Title = "Index"; } <h2>Index</h2> <h2>TestUser from fist database</h2> <table class="table"> <tr> <td>@Html.LabelFor(tuple => tuple.Item1.Id)</td> <td>@Html.DisplayFor(tuple => tuple.Item1.Id)</td> </tr> <tr> <td>@Html.LabelFor(tuple => tuple.Item1.Name)</td> <td>@Html.DisplayFor(tuple => tuple.Item1.Name)</td> </tr> </table> <h2>ImageModel from second database</h2> <table class="table"> <tr> <td>@Html.LabelFor(tuple => tuple.Item2.Id)</td> <td>@Html.DisplayFor(tuple => tuple.Item2.Id)</td> </tr> <tr> <td>@Html.LabelFor(tuple => tuple.Item2.url)</td> <td>@Html.DisplayFor(tuple => tuple.Item2.url)</td> </tr> </table>
Here is the result.
Best Regards,
YihuiSun
Contributor
2990 Points
855 Posts
Re: Adding second model to edit view - just for delete function
May 07, 2020 12:23 PM|YihuiSun|LINK
Hi, Baze72
Depending on your needs, you can use Tuple so that you can use two models from different database on one page.
I make a simple example, you can refer to it.
Controller
Page
Here is the result.
Best Regards,
YihuiSun