Is there a HTML helper in MVC that will render the value of the property with the name attribute. For example,
<td><div name="fileName">Hello World<div></td>
I'm currently using 'Display for' which just renders the text ...
public string FileName{ get; set; }
@Html.DisplayFor(x => Test.FileName)
The text is within a form. I'd like to retrieve the value when posting the form data.
You said:
The text is within a form. I'd like to retrieve the value when posting the form data.
It won't work like that. The div
will not be recognised as an input by the browser when you submit the form. Adding a name
attribute does not make it a valid form field.
If you want to post back the same value (but not have it be editable) then either put the value in a hidden field using a HiddenFor
helper (of course can you still use DisplayFor
at the same time to show the text to the user) or use a read-only textbox.