:獲得價值。當我有這樣一個DropDownList是相關型號的觀點,即不相關的模型
@Html.DropDownListFor(model => model.Group.Name, selectList)
我可以檢索的控制器值如下:
string SelectedGroupName = collection.GetValue("Group.Name").AttemptedValue;
但現在我有一個DropDownList是不相關的模型,但我需要的是價值,這是我的新下拉:
@Html.DropDownList("DDName", selectList)
如何檢索控制器中選定的值?是否有任何隱藏的領域或其他東西來將視圖傳遞給控制器?
編輯
這是我的看法:
@model PhoneBook.Models.Numbers
@{
ViewBag.Title = "Delete";
}
<h2>
Move And Delete</h2>
<fieldset>
<legend>Label of Numbers</legend>
<div class="display-label">
Delete Label And Move All Numbers with: @Html.DisplayFor(model =>
model.Title)</div>
<div class="display-field">
To @Html.DropDownList("DDName", selectlist)
</div>
</fieldset>
@using (Html.BeginForm()) {
<p>
<input type="submit" value="Move Numbers And Delete Label" name="MDbtn" />
</p>
}
這是我的控制器:
[HttpPost]
public ActionResult Delete(int id, FormCollection collection) {
var result = Request["DDName"];
//Use result
return RedirectToAction("Index");
}
,但結果設置爲null,爲什麼呢?
請求[「DDName」] –
@amit_g:那不行,我編輯問題並添加一些代碼並測試你的方式,請看。 – Saeid