关于vs2010中的MVC问题 [英] About MVC Problem in vs2010

查看:87
本文介绍了关于vs2010中的MVC问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个表:
国家/地区(国家/地区ID,国家/地区名称)在这里,国家/地区ID是主键
状态(状态ID,状态名称,国家/地区ID),此处国家/地区ID是外键

当我为州设计索引页面时:url(http://localhost:2010/States/Index)
StatesController.cs包含以下代码:

//我正在使用名称为db且函数为db的LINQ和datacontext对象.GetStates()返回状态对象的列表

I have two tables:
Countries(Country_ID,Country_Name) here Country_ID is primary key
States(State_Id,State_Name,Country_ID) here Country_ID is foreign key

When I design Index page for States: url(http://localhost:2010/States/Index)
StatesController.cs contains this code:

//I am using LINQ and datacontext object with name db and a function db.GetStates() returns list of State objects

index(){
 return view(db.GetStates());
}


应用程序的文件夹结构为:

Application-View-States-Index.aspx,当我执行此页面时,结果显示为Country_ID(1,India)


Folder Structure of Application is:

Application-View-States-Index.aspx and when I execute this page it shows result as Country_ID (1,India)

State_ID State_Name Country_ID
1        Punjab      1


但我想展示:


but I want to show:

State_ID State_Name Country_Name
1        Punjab     India


但模型对象或模型的项目对象仅包含一个States对象列表,该列表仅包含Country_ID而不是Country_Name.

如果有人拥有在Model,MVC中使用LINQ的示例应用程序,并且具有父子关系表.


but model object or item object of model contains only a list of States object which only contains Country_ID instead of Country_Name.

If anybody has any such sample application that using LINQ in Model, MVC and have parent child relationship tables.

推荐答案

我现在无法重现此内容,但是我"之前曾经碰到过它.

我弄清楚如何解决这个问题的方法是在模型上执行item.Country.Country_Name并运行...您将收到一条错误消息,这将引导您进行更正(这是需要做的事情) LINQ在某处未正确引用.

您可能还会在视图页面上检查继承(Inherits ="),因为您可能在使用通用的东西.

您正在使用哪个版本的VS2010(RC,RTM,Beta版)?

我做到了,无法复制:
1)创建一个新的MVC 2 Web应用程序
2)添加了一个数据库,并添加了上面具有关系的表
3)创建了DBML,添加了表(存在关系)
4)编译应用程序(以使MVC模板识别实体)
5)添加了StateRepository类,并添加了IEnumerable< state>. GetStates()方法.
6)添加了一个StateController
7)使用MVC工具创建状态视图.使用Models.State强烈键入视图,并使用列表作为模板.
8)然后我可以将Country_ID更改为Country.Country_Name

干杯,
-jc
I can''t reproduce this right now, but I''ve run into it before.

The way I figured out how to get past it is to do item.Country.Country_Name on the model and run...you should get an error message, which will lead you down the path to correct (it''s something to do with LINQ not being referenced properly somewhere.

You might also check the inheritance on the view page (Inherits="") as you might be using something generic.

What version of VS2010 are you using (RC, RTM, a Beta)?

I did this, and could not reproduce:
1) Create a new MVC 2 Web Application
2) Added a database, added the tables above with relationship
3) Created the DBML, added the tables (relationship was there)
4) Compiled the app (to get entities recognized by MVC templates)
5) Added a StateRepository class, added an IEnumerable<state> GetStates() method.
6) Added a StateController
7) Used MVC tooling to create View for States. Strongly typed the view with Models.State, used list as the template.
8) I can then change Country_ID to Country.Country_Name

Cheers,
-jc


这篇关于关于vs2010中的MVC问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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