views:

61

answers:

1

I have a a simple registration DTO with several sting properties: Username, Password, Email

To the view I pass in a strongly-typed ViewModel, that itself has the registrationDTO but also has additional properties to display in the view.

When using strongly typed html helpers, on the registrationDTO properties, I need to say Html.EditorFor (model => model.registrationDTO.Username), which would then generate the name and Id of the field as "registrationDTO.Username" and "registrationDTO_Username"

I basically have two questions:

  1. Is there a way to have the strongly typed HTML helper take in any object instead of the one that was passed into the view, so that I could pass in registrationDTO?

  2. If it is not possible, is there a way to have the HTML helper render the name and id without the first part (the "registrationDTO"). Almost similar to how the Prefix works in ModelBinding.

A: 

ad 1. you dont have to put object into HtmlHelper, you could use HtmlHelper and provide only the name and/or value for it

ad 2. the reason why HtmlHelper generates that profix is that your model contain class RegistrationDTO which has UserName, Password and Email. If you want to get rid off prefix, put this 3 fields into your model directly

Jack