I have a question on how to create custom View Helpers. I would like, in my Index View, to change my default dateTime format. I want to write my own Helper as I thought it was easy like in e.g. PHP. I did:
Created Class:
public static class CustomViewHelpers { public static MvcHtmlString returnDateString(string format, DateTime date) { return MvcHtmlString.Create(date.ToString(format)); } }I added it to the web.config,
I used it like that:
<p><em> Birth date</em> <%: CustomViewHelpers.returnDateString("D", Model.Birth_Date); %></p>
But I always get the error:
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1026: ) expected
But I think it is a wrong error because when I remove my line it works correctly and I see there are these ")" marks. Can you explain to me why this kind of helper does not work? Maybe you know a good tutorial on how to write your own helpers in ASP.NET MVC2?