tags:

views:

50

answers:

1

Hi, I'm doing a custom template in my MVC app, something like this:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<input type="text" id="date" />

And in my POCO I refer to this ascx file like this.

    [UIHint("DatePicker")]
    public DateTime CreatedOn { get; set;}

So I was wondering how can I send a parameter in this UIHint that I can put in the UIHint like this:

    [UIHint("DatePicker",null,"name","ThisIsTheNameValue")]
    public DateTime CreatedOn { get; set;}

And retrieve it in the ascx file to end with this:

 <input type="text" name="ThisIsTheNameValue" id="date" />

Thanks for your time.

+1  A: 

The UIHint attribute doesn't have any property that you can use for this, nor does the ModelMetadata class have any properties that would be applicable. The only suggestion I have would be to use an HtmlHelper extension to create the input and let it pull the name from the property on the model. This doesn't give you quite the control that you want, but it is reasonably simple. If that isn't sufficient, you may want to implement it via an HtmlHelper<T> extension that would allow you to use a custom attribute to define the name and construct the input yourself using a TagBuilder rather than use the templating engine.

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %> 
<%= Html.TextBox( string.Empty, Model, new { id = "date" } %>
tvanfosson