panjo
panjo

Reputation: 3515

take user input data from mvc textbox

My domain model has property Keywords of type string. Inside database is represented as comma separated value.

On mvc view page I'm collecting user entered keywords as every keyword inside separated textbox which will be replaced into one string value with commas between.

So I tried on inserting new record to collect keywords like this

<div class="editor-field">
    @Html.TextBox(@Model.Keywords, "")
</div>

but on http post controller action this property (Keywords) is empty? What I'm doing wrong here?

Upvotes: 0

Views: 683

Answers (1)

Giannis Paraskevopoulos
Giannis Paraskevopoulos

Reputation: 18411

You need to define a form for it.

For instance:

@using (Html.BeginForm("YourControllerAction", "YourControllerName", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<fieldset>
<div class="editor-field">
    @Html.TextBox(@Model.Keywords, "")
</div>
<input type="submit" value="Submit"/> 
</fieldset>
}

Upvotes: 2

Related Questions