我有具有車模一個DropDownList更改URL ID取決於DropDownList的選定值
@Html.DropDownList("Cars", (IEnumerable<SelectListItem>)ViewBag.Cars, "Select a Value", htmlAttributes: new { @class = "form-control" })
我需要的用戶還必須選擇一個值,如果他選擇一個特定的值發送值的ID URL的動作作爲參數
<a href="@Url.Action("Edit", "Registration", new { id = selected value of the dropdownlist item })" class="text-white"> Modify Registration</a> <a href="@Url.Action("Delete", "Registration", new { id = selected value of the dropdownlist item })" class="text-white"> Cancel Registration</a>
嗨,達林我不知道用戶將從下拉列表中選擇哪個值來評估'#ID#' –
您不需要評估任何內容。這只是一個佔位符,你應該像我的答案中所示的那樣進行硬編碼。這個想法是,你使用javascript訂閱下拉菜單的onchange事件,並且在這個回調函數中,你只需用實際選定的值替換佔位符,並用新的url替換錨點的'href'屬性即可。 –
這意味着我會採取代碼複製粘貼? –