MVC5 / Razor TextAreaFor null value

I have a very simple one @Html.TextAreaFor()

in the form and for some reason the textarea value never gets 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

it is always null and never really matters.

+3


source to share


1 answer


Your viewmodel must have properties, not fields, for model binding to work properly. So change public String quickSearch;

to public String quickSearch { get; set; }

.



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

+10


source







All Articles