0

I want to pass a property name as a string to @HTML.Textboxfor(). I cannot use @HTML.Textbox. The code could be something like @HTML.TextboxFor(model => model["PropertyName"]) or @HTML.TextboxFor("PropertyName") instead of @HTML.TextboxFor(model => model.PropertyName).

Again, I can't use @HTML.Textbox. Please help me out of this problem.

3
  • Is there any reason why you'd need to access it this way? Models are there for strongly typed objects, with property name, they're not arrays. Just trying to figure out what problem you're trying to solve by wanting to do this Commented Mar 5, 2014 at 14:16
  • @user3036342 I have property names stored in the database. I retrieve all property names from database, put them in a viewbag and then loop them through to generate controls on view using html helpers. Here i need to specify the property name from the viewbag. I have worked with Html.textbox and Html.dropdownlist but they don't work right. So i have to find a way towards HTML.Textboxfor and html.dropdownlistfor. Commented Mar 5, 2014 at 14:36
  • Ah I see. Did you try: @Html.TextBoxFor(model => model.PropertyName, new { id = model.PropertyID, Value= model.PropertyValue }) ? The property names you retrieve should go in as an IEnumerable(Of yourmodelcontaining the controls) which is strongly typed and accessable as per my example. Then you don't have to reference it weirdly. That or maybe post some sample code so I can better be of assistance Commented Mar 6, 2014 at 7:11

2 Answers 2

2

You can use simple html text control

<input type="text" value="@Model.ProperyName" name="PropertyName" id="PropertyName"/>
Sign up to request clarification or add additional context in comments.

Comments

0

Btw. this will also survive property name refactoring:

<input type="text" value="@Html.ValueFor(m => m.PropertyName)"
  name="@Html.NameFor(m => m.PropertyName)" />

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.