mardi 8 décembre 2015

How to read a specific field in ADO.NET Entity Data Model Object on Postback event

I have a dropdownlist that is populated from a database as:

Controller

PayrollDb pdb = new PayrollDb ();
var addBranchGui = new branch();
addBranchGui.BranchTypes = new SelectList(pdb.branchtypes,"Id", "Type");


View

<p>Branch Type:@Html.DropDownListFor(x => x.BranchType, Model.BranchTypes, "Choose an option")</p>

This codes correctly populates the dropdownload list. Problem arises when user selects an option in the dropdownlist and submits the form and I catch the input data on [HttpPost action method and insert it into a database table, it is the "Id" field that gets inserted when I want the "Type" field to be inserted.

I can understand that on Postback event, browsers is reading "Id" field. Can someone please guide me how I can command the browser to give me the "Type" field so I can insert that into database.

Aucun commentaire:

Enregistrer un commentaire