In my view I have the following HTML, and yes I know I could use an HTML helper but in this case I cannot use that because of some scripting we use on the page causes serious problems when I allow MVC to create the textarea.
@Html.TextBox("name", "", new { @placeholder = "name", @class = "formElement", @id="name"})
<textarea id="message" placeholder="comments" class="formElement"></textarea>
Then in my Controller I have setup a very basic line to print out the name and message.
[HttpPost]
public ActionResult Form(MessageViewModel model)
{
return Content("Name: " + model.name + " Message: " + model.message);
}
Name is accessible just fine because it is created with the HTML helper, but I cant access message, nothing is ever returned for it. Both name and message are defined in my ViewModel:
public string name { get; set; }
public string message { get; set; }
How do I access the text that is in my message textarea?
You should add a “name” attribute for the textarea. html elements are posted based on their names.