2

I made Index view by ADO.NET(model), MVC 5 controller use Entity Framework with views(controller). It is so easy way. but I got a problem when I try make two table (in a view). How can I show two tables in one view.
I wanna reference multiple models. But I can refer just one model as below (in view)

@ModelType IEnumerable(Of Ora_Connect.UsersData)

please advise

This is made by Visual Basic

added comment

Hello again. could you advice for me. I transf from C# to VB. So, I made masterview for multi table. I tried about 3days. but not solved yet thank you so much.

model

Public Class TestMulti_ViewModel

Public Property Test1 As IEnumerable(Of SCT_AUTH_OUT)
Public Property Test2 As IEnumerable(Of SCT_AUTH_OUT_ADD)

control

Namespace Controllers
Public Class TestMultiController
    Inherits Controller

    'Private db1 As New TestMulti_Entities1

    ' GET: TestMulti
    Function Index_Test(ByVal searchString As String) As ActionResult
        Dim mview = New TestMulti_ViewModel

        Return View(mview.Test1.ToList())
    End Function

End Class

@Modeltype IEnumerable(Of TestMulti_ViewModel)

View

@Modeltype IEnumerable(Of TestMulti_ViewModel)

 <table class="table">
     @Code Dim item As SCT_AUTH_OUT End Code

     <tr>
         <th>
             @Html.DisplayNameFor(Function(model As SCT_AUTH_OUT) model.ID)
         </th>
         <th>
             @Html.DisplayNameFor(Function(model As SCT_AUTH_OUT) model.PASS)
         </th>
         <th>
             @Html.DisplayNameFor(Function(model As SCT_AUTH_OUT) model.NAMEK)
         </th>
         <th></th>
     </tr>
     @code Dim mview = New TestMulti_ViewModel().Test1 end code


     @For Each item In mview
         @<tr>
             <td>
                 @Html.DisplayFor(Function(model As SCT_AUTH_OUT) item.ID)
             </td>
             <td>
                 @Html.DisplayFor(Function(model As SCT_AUTH_OUT) item.PASS)
             </td>
             <td>
                 @Html.DisplayFor(Function(modelItem As SCT_AUTH_OUT) item.NAMEK)
             </td>
             <td>
                               </td>
         </tr>

     Next
 </table>
kerry_kim
  • 23
  • 4
  • Did you looking for something like [this](https://stackoverflow.com/questions/4764011/multiple-models-in-a-view)? You can bind a parent viewmodel which contains multiple child viewmodels. – Tetsuya Yamamoto Feb 27 '19 at 05:42
  • Um..looks good way. I'll try it. if you have another way. pleas let me know :) I'll tell you later thanks! – kerry_kim Feb 27 '19 at 05:48
  • couldn't solve it. @TetsuyaYamamoto – kerry_kim Feb 27 '19 at 16:54
  • Anyway, do you really need a list of `TestMulti_ViewModel` objects? It doesn't seem that way. – ADyson Feb 27 '19 at 17:06
  • @ADyson I want to view by two models. continue fixed this code for using. but now I don't know how can I fix more. if you know, Let me know how can I make masterModel? by other models (example by C# ) but I'm not sure by VB. Please.... public class MasterMode{ public UserInfo UserInfo { get; set; } public LogDataServerDBEntities LogDataServerDBEntities { get; set; } } – kerry_kim Feb 28 '19 at 00:30
  • @ADyson I worked with this method. but I doesn't find out multiple tables make way https://learn.microsoft.com/ko-kr/aspnet/mvc/overview/older-versions/getting-started-with-aspnet-mvc3/vb/accessing-your-models-data-from-a-controller – kerry_kim Feb 28 '19 at 00:41
  • you need a single TestMulti_ViewModel which then _contains_ your two lists. ` @Modeltype TestMulti_ViewModel` in your view and `Function Index_Test(ByVal searchString As String) As ActionResult Dim mview = New TestMulti_ViewModel Return View(mview) End Function` in your controller would make more sense I think. Then you'll need to adapt the view code so it loops through each list in turn and displays a table for each one – ADyson Feb 28 '19 at 09:28
  • P.S. Unfortunately I cannot read that Microsoft link you gave me, because I cannot read or speak Korean. If you can find the English version I might be able to tell you if it's relevant or not. – ADyson Feb 28 '19 at 09:29
  • @ADyson You can read English ver If you click blue button on top right(left login). thanks you for your help. I'll try other ways. of course, with your advice Thank you again. – kerry_kim Feb 28 '19 at 21:11

0 Answers0