Tuesday, 15 January 2013

c# - Using model method name for id in a custom helper -


I created the following helper so I could have a date picker area:

  public Fixed MvcHtmlString DatePickerFor & LT; TModel & gt; (The HtmlHelper & lt; TModel & gt; Assistant, & lt; TModel; Object & gt; & gt; Property of the function; string minDate = "2012-01-01", string maxDate = "2100 / 01/01 ") {TModel Model = Assistant. ViewData.Model; Var Builder = New Tag Builder ("Input"); Builder. a quality. Add ("id", "id"); Builder. a quality. Add ("Type", "Date"); Return MvcHtmlString.Create (builder.ToString ()); }   

What I have to do is to generate the ID and name from the model method that I pass from my perspective as you can from any other EditorFor or RadioButtonFor areas. . Keeping this in mind, I call it this way:

  @ Html.DatePickerFor (model => model.EntryDate)   < P> Then in that case I should have the ID and name "EntryDate" I tried to see in  helper.ViewData  and other metadata and nothing near what I could do to work with met. The word "model method name" may be incorrect, please feel free to correct me.   

You may need to use the expression code to get the attribute name as the string Are there.

Here's the key bit, where the action is your lambda model = & gt; Model.EntryDate :

 on  action.Body; (MemberExpression); String name = expression    

No comments:

Post a Comment