【问题标题】:using jquery templates in a loop, need to prefill input items with ViewBag.values在循环中使用 jquery 模板,需要使用 ViewBag.values 预填充输入项
【发布时间】:2011-11-03 03:01:12
【问题描述】:

我有一个 jquery 模板,我正在循环 x 次以在表单上重复。当重新加载该表单时,它会自动运行循环以根据之前选择的内容显示所有输入,但我无法终生思考如何将值放入这些字段中。

使用这样的东西:

(string)ViewBag.myFieldValue{id}

不起作用,因为它认为它是一个 c# 对象(显然)。

我怎样才能做到这一点?

【问题讨论】:

    标签: asp.net-mvc razor jquery-templates


    【解决方案1】:

    一个 jquery 模板需要一个 json 对象来渲染。因此,您应该将 viewbag 中的值放入 json 对象中。更好的是,一个模板也可以接收一个 json 数组,并且会根据数组中对象的数量渲染 x 个模板。

    看看这篇博文,你很快就会明白的:

    An introduction to jquery templates

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-07
      相关资源
      最近更新 更多