将数据传输到ASP.NET MVC中的其他页面 [英] Transfer data to other page in ASP.NET MVC
本文介绍了将数据传输到ASP.NET MVC中的其他页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有3个模型dailyTransaction,Contract和ContractMonth。
我想将每日交易和合约中的一些数据传输到合约月份页面或表格但是我没有什么是错误的表是空的,没有任何数据。
我尝试过:
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>
推荐答案
如果我理解你,你想在控制器之间传输一些数据...注意,你的代码负责从实体获取相关数据(加载相关实体 - EF6 | Microsoft Docs [ ^ ])而不是使用临时数据(什么是ASP.NET MVC TempData [ ^ ]) 。
我强烈建议您阅读:关于在ASP.NET MVC应用程序中传递数据的各种方法的初学者教程 [ ^ ]
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[^]
我猜这个id没有数据。尝试使用您知道有数据的值进行硬编码,看看会发生什么。
I would guess there's no data for that id. Try hard coding with a value you know has data and see what happens.
这篇关于将数据传输到ASP.NET MVC中的其他页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文