Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > MVC 3.0 problem rendering partial view from _layout.vbhtml, models are inaccessible

Reply
Thread Tools

MVC 3.0 problem rendering partial view from _layout.vbhtml, models are inaccessible

 
 
Mobileboy
Guest
Posts: n/a
 
      09-01-2011
Hello group,

I’m new to asp.NET MVC. I use VS 2010 and MVC 3.0 (Visual Basic .NET).
I’m experimenting with partial views.
As an exercise, I want to create a partial view that displays the current
time.
I want to add this partial view to the masterpage. In terms of Razor, I want
to add the partial view to _Layout.html (below you find my questions).

I have the following model:
Namespace Models.ViewModels
Public Class TimeViewData

Public Function TimeAsstring() As String
Return Now.ToString
End Function


End Class
End Namespace


I created a strongly typed view _Timeview (_Timeview.vbhtml) with the
following code:

@ModelType CreatePartialView.Models.ViewModels.TimeViewData

@code
Dim TestObject As string

TestObject = Model.TimeAsstring
End Code

I want to display my parital view “_Timeview” on every page, so I added the
following code to _Layout.vbhtml:

<div id="TimeDesplay">
@Html.Partial("_Timeview)
</div>


Here are my QUESTIONS:
1. On the line “TestObject = Model.TimeAsstring” I always get a
nullreference exception, it doesn’t contain the current time.
What’s the problem?

2. A null reference exception indicates that the model is not set to an
object instance.
So I tried to change the code in _layout.vbhtml. The BIG problem is that
models.viewmodels.TimeviewData seems to be inaccessible from within
_layout.vbhtml since I don’t get code completion and I get the following
error:
Type 'models.viewmodels.TimeviewData' is not defined.
Why isn’t it accessible? What am I doing wrong?
<div id="TimeDesplay">
@code
Dim MyTimeviewData As New models.viewmodels.TimeviewData

Html.Partial("_Timeview", MyTimeviewData)
End Code


</div>






 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP.NET MVC - Add View: View Data Class RichB ASP .Net 7 09-21-2009 10:02 PM
Using python for writing models: How to run models in restricted python mode? vinjvinj Python 15 11-10-2005 09:57 AM
Re: Using python for writing models: How to run models in restrictedpython mode? Jean-Paul Calderone Python 0 11-07-2005 09:35 PM
MVC Multiple Models Steven Java 1 05-02-2005 11:08 PM
[ANN] Rails 0.9.2: End of requiring models, models in sessions, fixes David Heinemeier Hansson Ruby 0 12-23-2004 12:45 AM



Advertisments