troubleshooting Question

Display multi-table in view

Avatar of Peter Groves
Peter GrovesFlag for Canada asked on
* ASP .NET MVC 5ASP.NET
5 Comments1 Solution12 ViewsLast Modified:
If I display one table by itself it show ok. But I'm trying to figure out the syntax for
a mutiple table view.

public async Task<IActionResult> Index()
        {
            // return View(await _context.AnalSubTasks.ToListAsync());
            var getanalsub = (IEnumerable<AnalSubTask>)_context.AnalSubTasks.FromSqlRaw("spGetanalsub null").ToList();
                return View(getanalsub);
        } 

Open in new window

@foreach (var item in Model) {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.Ident)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.date_created)
            </td>

Open in new window

But if I use a multitable I can't figure out the syntax.

@model OASIS_MVC.View.ViewModel.mainviewmodelV


    <tbody>
        @foreach (var item in Model.SubTasks)
        {
            <tr>
                <td>
                   
                    @Html.DisplayFor(modelItem => Model.SubTasks.Ident)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => Model.SubTasks.date_created)
                </td> 

Open in new window


The controller part .
       public IActionResult Edit(int? id)
        {
            var tables = new mainviewmodelV
            {
                getanalmainV = (IEnumerable<Mainview>)_db3.mainviewmodelV.FromSqlRaw("spGetanalmain {0},{1}", null,id).ToList(),
                SubTasks = (IEnumerable<AnalSubTask>)_db3.AnalSubTasks.FromSqlRaw("spGetanalsub null").ToList()
        };
            return View(tables);
   
     }

Open in new window


If I put a break on the return I see the good data in the table variable.  I just can't figure out the right syntax to display it in the view.
The first table is the main one and has info I may edit. That is displayed using Div's
like this
 <label asp-for="getanalmainV.FirstOrDefault().Envelope" class="control-label col-xl-1 h-100 flex-fixed-width-item text-right bg-info"></label>
            <input asp-for="getanalmainV.FirstOrDefault().Envelope" class="form-control col-xl-1 h-100 flex-fixed-width-item" />
            <span asp-validation-for="getanalmainV.FirstOrDefault().Envelope" class="text-danger"></span>

Open in new window

The second table is just a list of non editable data for reference.

thanks
Pete
ASKER CERTIFIED SOLUTION
Peter Groves
Tech

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Log in to continue reading
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform for $9.99/mo
View membership options
Unlock 1 Answer and 5 Comments.
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
The Value of Experts Exchange in My Daily IT Life

Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>

Mike

Owner of Outages.IO
Phoenix, Arizona, United States
Member Since 2016
Join a full scale community that combines the best parts of other tools into one platform.
Unlock 1 Answer and 5 Comments.
View membership options
“All of life is about relationships, and EE has made a virtual community a real community. It lifts everyone's boat.”
William Peck

Member since 2004