在选择不同DropDownList中的项目之后,我想用DropdownList更改页面上的文本框(除此之外,更改发生的是bool是真的。)
$('#InvoiceNumber').replaceWith($(@Html.DropDownList("CategoryId", new SelectList(Model.Categories, "Value", "Text"), "Choose a category")));
但发生以下错误:
未捕获的SyntaxError:意外的标识符
为什么会这样?
答案 0 :(得分:0)
在replaceWith()
内部,您正在使用Html.DropDownList()
帮助程序方法生成使用jQuery选择器$()
包装的HTML。
jQuery选择器看起来是多余的:
$('#InvoiceNumber').replaceWith(@Html.DropDownList("CategoryId", new SelectList(Model.Categories, "Value", "Text"), "Choose a category"));
答案 1 :(得分:0)
试试这个:
$('#InvoiceNumber').replaceWith($('@Html.DropDownList("CategoryId", new SelectList(Model.Categories, "Value", "Text"), "Choose a category")'));
这也应该有效:
$('#InvoiceNumber').replaceWith('@Html.DropDownList("CategoryId", new SelectList(Model.Categories, "Value", "Text"), "Choose a category")');