如何在MVC的一个详细信息视图页面中显示多个表的信息 [英] How do I Display Info from multiple tables in one details view page in MVC

查看:128
本文介绍了如何在MVC的一个详细信息视图页面中显示多个表的信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个MVC应用程序,我已经成功地在VB.NET的一个视图页面中显示来自两个不同表的信息。但是我在尝试在应用程序中有两个表的详细信息视图页面中显示信息时遇到了麻烦。我认为我遇到的麻烦就是ID。



我将要显示的所有信息都是关于一个特定的ID,因此在视图页面中,modelType将会是这样的:

 @ ModelType clientApp.iTracker.ICClass 





而不是:

 @ ModelType IEnumerable( of  clientApp.iTracker.ICClass)





这是因为我不需要foreach来显示信息,因为它应该特定于问题的ID。



目前我想要做的是在控制器中获取所选的特定ID:



  Dim  IssTable  As  IssueTable = dbS.IssueTables.Find(id)





在上一页中,我将在视图中选择如下问题:



 @ Html.ActionLink(项目.iTable.ProjectTypeID.ToString(),  DetailsIssue 使用 {。id = item.iTable.IssueID})





然后在详细视图中我试图显示如下信息:



 @ Html.DisplayFor(< span class =code-keyword>功能(型号)model.iTable.Created)





我的班级看起来像这个;



 命名空间 IssueTracker 
公开 IssueComments
公共 cTable 作为 CommentTable
公开 iTable 作为 IssTable
结束
结束 命名空间





但这不起作用。在MVC VB.NET的详细视图页面中显示来自两个表的信息的正确方法是什么?

解决方案

您可以对给定问题使用ViewModel方法。

你可以在这里了解更多关于问题的信息(C#代码)

http://rahulrajatsingh.com/2014/06/a-beginners-tutorial-on-various-ways-的-通过数据入-ASP净MVC的应用程序/

I have an MVC application and I have it successfully displaying information from two different tables in one view page in VB.NET. But I am having trouble trying to display information in a details view page with two tables in the application. I think the trouble I am having is with the ID's.

All the information I will be displaying will be about one specific ID, therefore in the view page the modelType will be like this:

@ModelType clientApp.iTracker.ICClass



instead of:

@ModelType IEnumerable(Of clientApp.iTracker.ICClass)



This is because I do not need a foreach to display the information as it should be specific to the ID of the issue.

Currently what I am trying to do is in the controller to get the specific ID selected:

Dim IssTable As IssueTable = dbS.IssueTables.Find(id)



In the previous page I will select the issue in the view like this:

@Html.ActionLink(item.iTable.ProjectTypeID.ToString(), "DetailsIssue", New With {.id = item.iTable.IssueID})



Then in the detailed view I am trying to display the information like this:

@Html.DisplayFor(Function(model) model.iTable.Created)



My class looks like this;

Namespace IssueTracker
    Public Class IssueComments
        Public cTable As CommentTable
        Public iTable As IssTable
    End Class
End Namespace



But this is not working. What is the correct way to display information from two tables in a detailed view page in MVC VB.NET?

解决方案

You can use ViewModel approach for the given problem.
You can know more about problem here (C# Code)
http://rahulrajatsingh.com/2014/06/a-beginners-tutorial-on-various-ways-of-passing-data-in-asp-net-mvc-application/


这篇关于如何在MVC的一个详细信息视图页面中显示多个表的信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆