Edit one more time:
So it looks like I have figured out the address part too, in the class I have:
Public ReadOnly Property addresses As IEnumerable(Of Address)
Get
Return _these_addresses
End Get
End Property
And in the template I have:
<% For Each item In Model.addresses%>
<tr>
<td>
<a href='<%: Url.Action("Edit", "Address", New With { .pid=Model.ContactID, .id=item.AddressID }) %>'>
<img src='<%: Url.Content("~/Content/Images/Edit.jpg") %>' alt="Edit" />
</a>
<a href='<%: Url.Action("Details", "Address", New With { .pid=Model.ContactID, .id=item.AddressID }) %>'>
<img src='<%: Url.Content("~/Content/Images/Detail.jpg") %>' alt="Details" />
</a>
<a href='<%: Url.Action("Delete", "Address", New With { .pid=Model.ContactID, .id=item.AddressID }) %>'>
<img src='<%: Url.Content("~/Content/Images/Delete.jpg") %>' alt="Delete" />
</a>
</td>
<td>
<%: item.Street%>
</td>
<td>
<%: item.City%>
</td>
<td>
<%: item.StateID%>
</td>
<td>
<%: item.CountryID%>
</td>
<td>
<%: item.Zip%>
</td>
</tr>
<% Next%>
</table>
Edit Again:
I added this for every field in contact to the class and it is working...I just need to figure out the list of addresses now...
Public ReadOnly Property FirstName() As String
Get
Return _this_contact.FirstName
End Get
End Property
E D I T:
I about have it figured out:
I took a shot in the dark and made a ContactViewModel based of C examples I have found in research on how to do this
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports TotallyAwesomeCRM.Contact
Imports TotallyAwesomeCRM.Address
Public Class ContactViewModel
Public contact As Contact
Public address As Address
Private _this_contact As Contact
Private _these_addresses As System.Linq.IQueryable(Of Address)
Sub New(ByVal this_contact As Contact, ByVal these_addresses As System.Linq.IQueryable(Of Address))
' TODO: Complete member initialization -this was added by the framework for me when I tried to call this class - I don't know what to do here - resources?
_this_contact = this_contact
_these_addresses = these_addresses
End Sub
End Class
So in my controller I:
Function Details(ByVal id As Integer) As ActionResult
Dim this_contact = GetContact(id)
Dim these_addresses =
From address In addressDataContext.Addresses, xref In addressDataContext.ContactAddressesXrefs
Where address.AddressID = xref.AddressID And xref.ContactID = id
Select address
Dim viewModel = New ContactViewModel(this_contact, these_addresses)
Return View(viewModel)
End Function
And in the template it found the contact when I started typing Model.contact
But it gave me an error there: NullReferenceException: Object reference not set to an instance of an object.
It shouldn't be null...Please help me figure out the TODO
================================================================================= O R I G I N A L P O S T:
This is my first .NET venture ever. Everything I have done thus far I have figured out.
OK I have contacts, and contacts can have many addresses. I would like to display those addresses when I am viewing the detail of a Contact I would also like to have a container that is a list view of it's addresses. From that list view I want to be able to edit/delete/view the address.
My database structure is:
Tables:
Contacts
<contains contact info and PK>
Addresses
<contains address info and PK>
ContactAddressesXref
ContactID
AddressID
I have basically been editing the skeleton files the ASP.NET MVC empty application provides me
So here is the last thing I have tried in my Contact controller:
'
' GET: /Contacts/Details/5
Function Details(ByVal id As Integer) As ActionResult
Dim this_contact =
From contact In dataContext.Contacts, address In addressDataContext.Addresses, xref In addressDataContext.ContactAddressesXrefs
Where address.AddressID = xref.AddressID And xref.ContactID = id
Select contact, address
Return (View(this_contact))
End Function
What I really wanted to do was query the addresses separately and send them in as their own set. I don't know if doing this is the right thing to do, but when I tried to send in two models it freaked out.
Which fails of course because the view has this in it:
<%@ Page Title="" Language="VB" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage(Of IEnumerable (Of TotallyAwesomeCRM.Contact))" %>
I tried:
Inherits="System.Web.Mvc.ViewPage(Of IEnumerable (Of TotallyAwesomeCRM.Contact, Of TotallyAwesomeCRM.Address))
It said:
'InitializeCulture' is not a member of 'ASP.views_contacts_details_aspx'.
So OK I tried:
Inherits="System.Web.Mvc.ViewPage"
And it throws and error here:
<div class="display-field"><%: Model.FirstName%></div>
Of course, so Am I wrong in the controller? I know I can't have just System.Web.Mvc.ViewPage(Of IEnumerable (Of TotallyAwesomeCRM.Contact)) that it will have to accept more than that. I tried jacking with the Model.FirstName part saying Contact.FirstName, but that didn't come up in the drop down when I started writing Contact. I could do this easily in other languages, .Net seems to be a different ball game. Please help!