1
我做的:如何添加DropDownList而不綁定到ViewData?
@Html.DropDownList("ddBrand", (IEnumerable<SelectListItem>)ViewBag.Brands, new {onchange = "JavaScript:Act()"})
但是,當我按下提交,需要根據模型中場「ddBrand」。
如何在不綁定ViewData的情況下將DropDownList添加到View? (在視圖模型中不添加字段「ddBrand」)
我創建了一些小功能,它返回字符串。當我做@ MyDropDownList.Create(「ddType」,「JavaScript:DisplayTextType()」,ViewBag.VehicleTypes)時,它將它作爲文本插入(將「<」替換爲<)。我該如何解決它? –
@Kak你的'Create'方法應該返回'MvcHtmlString'而不是'string'。由於Razor語法對普通字符串進行編碼。 – Eranga