Helper Html.Truncate does not compile

Aug 26, 2010 at 7:47 PM

The original view StoreManager\Index.aspx had <%@ Import Namespace="MvcMusicStore.Helpers" %> in it but your version has not. The Html.Truncate was causing an error so I put this import namespace in but that gave an error saying that the namespace does not exist, but I have the folder Helpers with HtmlHelpers.cs in it. Is there some other other way you have implemented it?

 

Many thanks

Aug 29, 2010 at 3:35 PM

I have found the problem the namespace declaration for HtmlHelpers.cs should be "MvcMusicStore.Helpers" and you do not need the <%@ Import Namespace="MvcMusicStore.Helpers"%> in Index.aspx if the namespace is added in the web.config

Chris

Coordinator
Aug 31, 2010 at 5:30 PM

Yes - I'm changing that in the next release of the tutorial to move the helpers namespace reference into the web.config.

Sep 25, 2010 at 12:50 PM

John,

Very nice tutorial. But I am facing some problems following it to the word. May be it is because I am using Visual Studio 2008. Anyway so far it's going good.

The reason for this note is : I did not understand, what you are going to change in the next release and why, because, things are fine as per the tutorial in the HtmlHelper aspect. Moving the import statement from view-page to web.config is not necessary from the MVC tutorial point of view. Maybe I have misunderstood this post or Chris.

Would appreciate a clarification if time permits.

Also there are other steps which were missing from the tutorial. May be they are due to VS2010/2008 difference. If you are interested, I will list them out for you.

Respectfully,

Tushar G. Walavalkar

Sep 25, 2010 at 7:22 PM
Hi Tushar
You are right that you do not need to put the namespace into the web.config but if you do it saves adding it to every screen or class that uses it. I think this is a feature of VS2010. I really like this feature as it gives you a single place to look for your namespaces.
Chris

From: [email removed]
Sent: Saturday, September 25, 2010 1:50 PM
To: [email removed]
Subject: Re: Helper Html.Truncate does not compile [mvcmusicstore:224986]

From: tushargw

John,

Very nice tutorial. But I am facing some problems following it to the word. May be it is because I am using Visual Studio 2008. Anyway so far it's going good.

The reason for this note is : I did not understand, what you are going to change in the next release and why, because, things are fine as per the tutorial in the HtmlHelper aspect. Moving the import statement from view-page to web.config is not necessary from the MVC tutorial point of view. Maybe I have misunderstood this post or Chris.

Would appreciate a clarification if time permits.

Also there are other steps which were missing from the tutorial. May be they are due to VS2010/2008 difference. If you are interested, I will list them out for you.

Respectfully,

Tushar G. Walavalkar

Coordinator
Sep 25, 2010 at 11:55 PM

Chris, Tushar -

Right, both ways work. The web.config approach is a little cleaner for two reasons:

  • You can use your helper in all your views without having to add an import statement
  • If you put all several helpers in one namespace, you can use them all in all your views without any import statements

This has actually been available since ASP.NET 2.0, if you can believe it: http://msdn.microsoft.com/en-us/library/ms164642.aspx

- Jon

 

 

 

 

Sep 26, 2010 at 2:03 AM

Jon (sorry about John earlier),

Glad to know that I didn't misunderstand.

Yes this feature has been around since ASP.NET 2.0 but VS2005 intellisense had issues coming up with right entities in the list when you put the namespace in web.config. Compilation worked fine. Never checked the same in VS2008. But just thought it easier, for the intellisense to work, to put it on the page. Hopefully VS2010 does it better.

- Tushar G. Walavalkar