[英]Data from Controller not visible in View - ASP MVC
I'm just starting with MCV in ASP and just on my first try I'm having problems when parsing data from controller to view. 我只是从ASP中的MCV开始,并且在我第一次尝试时,从控制器到视图解析数据时遇到问题。 BTW, I'm using a entity model from a MySql Database.
顺便说一句,我正在使用MySql数据库中的实体模型。
Controller 控制者
Namespace MvcRad
Public Class ProyectosController
Inherits System.Web.Mvc.Controller
Function Index() As ActionResult
Dim ed As New visrunEntities
ViewData("values") = From p In ed.proyectos _
Select p
Return View()
End Function
End Class
End Namespace
View 视图
<div>
<% For Each p In ViewData("values")
p.Codigo()%> <br/>
<%Next%>
</div>
I tried printing a random value to know if it was looping like this (There are 4 records on table): 我尝试打印一个随机值,以了解它是否像这样循环(表上有4条记录):
<div>
<% For Each c In ViewData("values")%>
A<br/>
<%Next%>
</div>
And it works, because I get: 它行得通,因为我得到了:
A
A
A
A
What am I missing? 我想念什么?
您必须将ViewData("values")
强制转换为ed.proyectos _的列表以打印其属性
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.