所以在我看来,我有一个下拉列表。所以我想为默认选择添加一个 ID。这是我的控制器:
public ActionResult AddRemoveContract()
{
var companyQuery = db.tblCompanies.OrderBy(c => c.CompanyName);
ViewData["AllCompany"] = new SelectList(companyQuery, "PKComID", "CompanyName");
return View();
}
这是我的观点:
@Html.DropDownList("ddlCompany", ViewData["AllCompany"] as SelectList, "--Select Company--", new { @onchange = "getSite(this.value);" })
我选择的列表是这样的
<select id="ddlCompany" onchange="getSite(this.value);" name="ddlCompany">
<option value="">--Select Company--</option> // want to add value="0"
<option value="9">Company A</option>
<option value="11">Company B</option>
</select>
我想为“--Select Company--”添加值“0”。怎么做?