HtmlHelpers Code for StoreManager V1.0 Bug

Oct 20, 2010 at 12:06 AM
First, I want to thank all of you who put this tutorial together. Very  easy to follow. I'm new at C# but have done some Java in years past.

Following the tutorial I discovered that the HtmlHelpers Class and the code in StoreManager's Index view were not connecting.

Here what in the tutorial didn't work:

HtmlHelpers Class

using System.Web.Mvc;
namespace MvcMusicStore.Helpers
{
public static class HtmlHelpers
{
public static string Truncate(this HtmlHelper helper, string input, int length)
{
if (input.Length <= length)
{
return input;
}
else
{
return input.Substring(0, length) + "...";
}
}
}
}
StoreManager View Index

<td><%: Html.Truncate(item.Title, 25) %></td>

<td><%: Html.Truncate(item.Artist.Name, 25) %></td>

Here is what worked for me....
HtmlHelpers Class

namespace

 

MvcMusicStore.Helpers

{

 

public static class

HtmlHelpers

{

 

public static string Truncate(string input, int

length)

{

 

if

(input.Length <= length)

{

 

return

input;

}

 

else

{

 

return input.Substring(0, length) + "..." <!--Html.Truncate(item.Title, 25)-->

;

}

}

}

}



StoreManager View Index



<td >

<%: HtmlHelpers .Truncate( item.Title, 25) %> </td >

 

 

<td ><%: HtmlHelpers.Truncate(item.Artist.Name, 25) %>  

 

</td>



 I hope this helps.