0

在不同的 DropDownList 中选择一个项目后,我想用 DropdownList 更改页面上的文本框(发生的更改是 bool 是真的,除此之外)。

$('#InvoiceNumber').replaceWith($(@Html.DropDownList("CategoryId", new SelectList(Model.Categories, "Value", "Text"), "Choose a category")));

但是会出现以下错误:

未捕获的 SyntaxError:意外的标识符

为什么会出现这种情况?

4

2 回答 2

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")');
于 2013-07-24T15:00:49.223 回答
0

在您的内部,您replaceWith()正在使用Html.DropDownList()helper 方法生成用 jQuery 选择器包装的 HTML $()

jQuery 选择器看起来是多余的:

$('#InvoiceNumber').replaceWith(@Html.DropDownList("CategoryId", new SelectList(Model.Categories, "Value", "Text"), "Choose a category"));
于 2013-07-24T10:30:48.857 回答