3

I have a very basic @Html.TextAreaFor() on a form, and for some reason, the text area's value never makes it to my controller.

VIEW

<p class="SmallText">(Multiple Entries Allowed)</p>
@Html.TextAreaFor(x => x.quickSearch, new { cols = 30, @rows = 5 })

VIEW-MODEL

public String quickSearch;

CONTROLLER

public ActionResult FindRecord(FindRecordViewModel Model)
{       
    var ImNotCrazy = Model.quickSearch;
}

The problem is that when I debug Model.quickSearch is always null and never has a value.

1 Answer 1

10

Your view model has to have Properties, not fields, to work properly with model binding. So change public String quickSearch; to public String quickSearch { get; set; }.

Also, you should use standard naming conventions and change the name of the field to QuickSearch

Sign up to request clarification or add additional context in comments.

2 Comments

Oh my god, I can't believe I missed the obvious answer right in front me. That was it! The old second pair of eyes thing ;) As far as the naming convention goes, I didn't actually write this code, just helping a coworker figure out why it wasn't working.
@mituw16 That would be a third pair of eyes then ;)

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.