Click here to Skip to main content
15,890,186 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have 3 models dailyTransaction , Contract , and ContractMonth .

I want transfer some of data from daily Transaction and Contract to the Contract Month page or table But i do not what is the wrong the table is empty and there no any data .

What I have tried:

This is my Contract Month Controller:
<pre>
     public ActionResult Index(int id)
        {
            var contractMonth = _context.ContractMonth.Where(c => c.ContractsId == id).Include(s => s.contracts).Include(d => d.dailyTransactions).ToList();

            return View(contractMonth);
        }


This is the view :

<table class="table table-bordered f" cellspacing="0" id="employeetable">
    <thead>
        <tr>
            <th>@Html.DisplayNameFor(model => model.ContractsId)</th>

            <th>@Html.DisplayNameFor(model => model.Monthe)</th>
            <th>@Html.DisplayNameFor(model => model.Amount)</th>
            <th>@Html.DisplayNameFor(model => model.Receipt)</th>

        </tr>
    </thead>
    <tbody>
        @foreach (var item in Model)
        {
            <tr>
                <td>
                    @Html.DisplayFor(modelItem => item.contracts.Contract_Num)
                </td>

                <td>
                    @Html.DisplayFor(modelItem => item.dailyTransactions.Date)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.contracts.AmountOfRent)
                </td>


            </tr>
        }

    </tbody>
</table>
Posted
Updated 28-Apr-19 23:04pm
Comments
F-ES Sitecore 29-Apr-19 5:32am    
We don't have access to your data or what you're doing so you'll need to do some debugging. Put a breakpoint in your Index method and first thing to check is that "id" has a value that you are expecting. If it doesn't then the problem is with whatever is creating the link to that controller method. If it does have a value but contractMonth then you need to go through your data and table joins to see if there is anything you are missing there. If contractMonth does have data then step through the code in your view to try and see what is going wrong.
Member 14317227 1-May-19 1:47am    
Thank you , O will try do that

If i understand you well, you want to transfer some data between controllers... Note, that your code is responsible for getting related data from entities (Loading Related Entities - EF6 | Microsoft Docs[^]) instead of using temporary data (What is ASP.NET MVC TempData[^]).

I'd strongly recommend to read this: A Beginner's Tutorial on Various Ways of Passing Data in ASP.NET MVC Application[^]
 
Share this answer
 
Comments
Member 14317227 1-May-19 1:49am    
OK Thank you
Maciej Los 1-May-19 6:55am    
You're very welcome.
I would guess there's no data for that id. Try hard coding with a value you know has data and see what happens.
 
Share this answer
 
Comments
Member 14317227 1-May-19 1:49am    
No there are some data , O do not understand what you mean

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900