Good Morning everybody.
I’m a beginner in .Net languages and need an example to be able to go further.
So, my objective is to display dates and comments from a datatable, below general information about a client.
The view needs to become something like that :
name firstname :
adress :
phone number :
…
date1
comment1
date2
comment2
…
It was easy to automatically generate a strongly typed view with the general data. Now, I don’t get how to display the comments below.
Here is what I’ve already done into the controller
' GET: /Contacts/Details/5
Function Details(id As Integer) As ActionResult
Dim contact As contact = db.contact.Single(Function(c) c.idContact = id)
Dim listMeet = New List(Of meeting)
listMeet = (From d In db.meeting
Where d.FK_meet_contact = id
Select d).ToList()
ViewBag.listeMeeting = listMeet
Return View(contact)
End Function
Into the view, I dis plenty of wrong things… Let’s show you the last one :
@ModelType MvcApplication4.contact
@Code
ViewData("Title") = "Details"
Dim list As List(Of Object) = ViewBag.listeMeeting
Dim ligne As ListItemCollection
End Code
[…]
<fieldset>
<legend><button onclick="togglefield('Meet')">Meetings</button></legend>
<div class="Meet">
@For Each ligne In ViewBag.listeMeeting
@Html.Raw(ViewBag.listeMeeting)
Next (ligne)
</div>
</fieldset>
What haven’t I well understood?
ps : I’m not a native english speaker, so, sorry if my english sucks
You could use a view model instead of
ViewBag:and then populate this view model in your controller and pass to the view for displaying:
and then have your view strongly typed to the view model: